我有问题.. 我想结合两个数组..
多维
阵列1。
Array
(
[0] => 1
[1] => 2
[2] => 1
[3] => 2
[4] => 1
)
数组2
Array
(
[0] => asdf
[1] => asdfa
[2] => asdf
[3] => asdf
[4] => asdfasdf
)
我需要这样的解决方案......
Array
(
[1] => asdf
[2] => asdfa
[1] => asdf
[2] => asdf
[1] => asdfasdf
)
如果在多维数组中有任何解决方案,请告诉我。
组合两个数组后我需要使用foreach或任何方法,我想在数据库中插入数组数据
喜欢这个..
ID | Value | S_ID
--------------------
1 | asdf | 1
2 | asdfa | 2
3 | asdf | 1
4 | asdf | 2
4 | asdfasdf | 1
我很困惑,我从最近6个小时尝试了很多功能和方法,但没有运气:( ..
答案 0 :(得分:2)
一起迭代两个数组并创建一个多维数组:
$newarray = array();
foreach($array1 as $key => $value) {
$newarray[] = array(
'Value' => $value,
'S_ID' => $array2[$key],
);
}
print_r($newarray);