PHP数组结合3个数组 [英] php array combine 3 arrays
本文介绍了PHP数组结合3个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将获得3个数组$ _POST数组。
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
)
我需要获取它并添加到mysql中。因此,我认为需要将3个数组组合为一个数组。
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)
)
我尝试了array_combine(),但这仅支持两个数组
I tried array_combine(), but that's just support two arrays
推荐答案
简单使用 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
}
这篇关于PHP数组结合3个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文