我有一些代码,但我认为它可能更简单。
也许你可以打扰我,做到这一点。
$array_product = array ('1,2,3,4,5','5,7,8,9,5','1,5,7,8,9');
$table = array();
for($i = 0;$i<count($array_product) ;$i++)
{
$arr = preg_split('/,/',$array_product[$i]);
foreach($arr as $val)
{
$table[$i][]=$val;
}
}
print_r($table);
谢谢!
答案 0 :(得分:2)
$array_product = array ('1,2,3,4,5','5,7,8,9,5','1,5,7,8,9');
$table = array_map(function($val) {
return explode(",", $val);
}, $array_product);
print_r($table);
答案 1 :(得分:1)
$table = array_map(function($x){return explode(',',$x);}, $array_product);
答案 2 :(得分:0)
您可以将其简化,可读和优化,如下所示:
$arrayProduct = array ('1,2,3,4,5', '5,7,8,9,5', '1,5,7,8,9');
$table = array();
foreach ($arrayProduct as $values) {
$arr = explode(',', $values);
$table[] = $arr;
}
print_r($table);