php如何把一组数组拆分为两部分分别存入数据库中?

2025-05-13 21:30:07
推荐回答(3个)
回答1:

$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 )楼上大哥的是对的~~

回答2:

for($i=0;$i<=4;$i++){$a[]=strtr($arr[i],"#1_1","");$b[]=strtr($arr[i+5],"#2_1","");}

回答3:

程序$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)