php如何把一组数组拆分为两部分分别存入数据库中?
Array([0]=>4,0,9#1_1[1]=>4,5,5#1_1[2]=>4,5,1#1_1[3]=>7,2,4#1_1[4]=>4,4,3#1_1[5]=>8,8,...
Array ( [0] => 4,0,9#1_1 [1] => 4,5,5#1_1 [2] => 4,5,1#1_1 [3] => 7,2,4#1_1 [4] => 4,4,3#1_1 [5] => 8,8,0#2_1 [6] => 2,2,9#2_1 [7] => 0,0,6#2_1 [8] => 0,0,7#2_1 [9] => 3,3,8#2_1 )
这样一组数据,我想把#1_1 的和 #2_1 的分别存到一个表的两个字段中
php如何实现?
存入的时候需要去除#1_1 和#2_1 展开
这样一组数据,我想把#1_1 的和 #2_1 的分别存到一个表的两个字段中
php如何实现?
存入的时候需要去除#1_1 和#2_1 展开
3个回答
2013-08-27
展开全部
<?php$data = array("4,0,9#1_1", "4,5,5#1_1","4,5,1#1_1", "7,2,4#1_1", "4,4,3#1_1", "8,8,0#2_1","2,2,9#2_1","0,0,6#2_1", "0,0,7#2_1","3,3,8#2_1" );$result1 = array();
$result2 = array();
foreach($data as $key=>$value)
{
$str1 = '#1_1';
$str2 = '#2_1'; if(strpos($value,$str1))
{
$tmp = str_replace($str1,'',$value);
$result1[] = $tmp;
}
else if(strpos($value,$str2))
{
$tmp = str_replace($str2,'',$value);
$result2[] = $tmp;
}
}
print_r($result1);
print_r($result2);
?>
结果:Array ( [0] => 4,0,9 [1] => 4,5,5 [2] => 4,5,1 [3] => 7,2,4 [4] => 4,4,3 ) Array ( [0] => 8,8,0 [1] => 2,2,9 [2] => 0,0,6 [3] => 0,0,7 [4] => 3,3,8 )楼上大哥的是对的~~
$result2 = array();
foreach($data as $key=>$value)
{
$str1 = '#1_1';
$str2 = '#2_1'; if(strpos($value,$str1))
{
$tmp = str_replace($str1,'',$value);
$result1[] = $tmp;
}
else if(strpos($value,$str2))
{
$tmp = str_replace($str2,'',$value);
$result2[] = $tmp;
}
}
print_r($result1);
print_r($result2);
?>
结果:Array ( [0] => 4,0,9 [1] => 4,5,5 [2] => 4,5,1 [3] => 7,2,4 [4] => 4,4,3 ) Array ( [0] => 8,8,0 [1] => 2,2,9 [2] => 0,0,6 [3] => 0,0,7 [4] => 3,3,8 )楼上大哥的是对的~~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-27
展开全部
for($i=0;$i<=4;$i++){$a[]=strtr($arr[i],"#1_1","");$b[]=strtr($arr[i+5],"#2_1","");}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-27
展开全部
程序<?php$data = array("4,0,9#1_1", "4,5,5#1_1","4,5,1#1_1", "7,2,4#1_1", "4,4,3#1_1", "8,8,0#2_1","2,2,9#2_1","0,0,6#2_1", "0,0,7#2_1","3,3,8#2_1" );$result1 = array();
$result2 = array();
foreach($data as $key=>$value)
{
$str1 = '#1_1';
$str2 = '#2_1';
if(strpos($value,$str1))
{
$tmp = str_replace($str1,'',$value);
$result1[] = $tmp;
}
else if(strpos($value,$str2))
{
$tmp = str_replace($str2,'',$value);
$result2[] = $tmp;
}
}var_dump($result1);
var_dump($result2);?>结果array 0 => string '4,0,9' (length=5) 1 => string '4,5,5' (length=5) 2 => string '4,5,1' (length=5) 3 => string '7,2,4' (length=5) 4 => string '4,4,3' (length=5)array 0 => string '8,8,0' (length=5) 1 => string '2,2,9' (length=5) 2 => string '0,0,6' (length=5) 3 => string '0,0,7' (length=5) 4 => string '3,3,8' (length=5)
$result2 = array();
foreach($data as $key=>$value)
{
$str1 = '#1_1';
$str2 = '#2_1';
if(strpos($value,$str1))
{
$tmp = str_replace($str1,'',$value);
$result1[] = $tmp;
}
else if(strpos($value,$str2))
{
$tmp = str_replace($str2,'',$value);
$result2[] = $tmp;
}
}var_dump($result1);
var_dump($result2);?>结果array 0 => string '4,0,9' (length=5) 1 => string '4,5,5' (length=5) 2 => string '4,5,1' (length=5) 3 => string '7,2,4' (length=5) 4 => string '4,4,3' (length=5)array 0 => string '8,8,0' (length=5) 1 => string '2,2,9' (length=5) 2 => string '0,0,6' (length=5) 3 => string '0,0,7' (length=5) 4 => string '3,3,8' (length=5)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询