我有一个问题…我想合并两个数组。
多维数组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个小时,但没有运气:(..
一起遍历两个数组并创建一个多维数组:
$newarray = array();
foreach($array1 as $key => $value) {
$newarray[] = array(
'Value' => $value,
'S_ID' => $array2[$key],
);
}
print_r($newarray);