php数组合3个数组[关闭]
问题描述:
will be get 3 array $_POST array.
$_POST["name"]=> array (
[0] => product_1
[1] => product_2
[2] => product_3
)
$_POST["content"]=> array (
[0] => content_1
[1] => content_2
[2] => content_3
)
$_POST["price"]=> array (
[0] => 100
[1] => 200
[2] => 300
)
I need to fetch it and add to mysql. So, I think that need to combine 3 array to one array.
so I need get this format? and how can I do? :
$array =>(
[0] => (product_1,content_1,100)
[1] => (product_2,content_2,200)
[2] => (product_3,content_3,300)
)
I tried array_combine(), but that's just support two arrays
答
simple use foreach
$new_array=array(); //create new array
foreach($_POST['name'] as $key=>$val){ //loop any one of post
$new_array[]=array($_POST['name'][$key],$_POST['content'][$key],$_POST['price'][$key]); //create new array with the help of $key
}