您的当前位置:首页正文

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

2013-08-24 来源:个人技术集锦

有网友碰到这样的问题“php如何把一组数组拆分为两部分分别存入数据库中?”。小编为您整理了以下解决方案,希望对您有帮助:

解决方案1:

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

显示全文