嗨,所有的stackoverflow成員,請幫我解決有關數組操作的問題。PHP數組合並/合併
stores_array:
Array
(
[0] => store1
[1] =>store2
)
items_array:
Array
(
[electronics]=>led tv
[cosmetics]=>eyeliner
[fruits]=>apple
[vegetables]=>cabbage
)
這裏是我到目前爲止有:
$new_array = array();
foreach($stores_array as $t) {
$new_array[$t] = $items_array;
}
echo '<pre>';
print_r($new_array);
echo '<pre/>';
這裏是輸出:
Array
(
[store1] => Array
(
[electronics]=>led tv
[cosmetics]=>eyeliner
[fruits]=>apple
[vegetables]=>cabbage
)
[store2] => Array
(
[electronics]=>led tv
[cosmetics]=>eyeliner
[fruits]=>apple
[vegetables]=>cabbage
)
)
這裏就是我想要實現:
我想添加一些其他的每個數組中的值。
請參閱我打算添加的箭頭。
Array
(
[store1] => Array
(
[electronics]=>led tv
[cosmetics]=>eyeliner
[fruits]=>apple
[vegetables]=>cabbage
[store]=>store1 <------- how can i add these?
)
[store2] => Array
(
[electronics]=>led tv
[cosmetics]=>eyeliner
[fruits]=>apple
[vegetables]=>cabbage
[store]=>store2 <------- how can i add these?
)
)
感謝大家提前..
這不是多餘的信息嗎? –
'foreach($ new_array as $ store => $ store_info)'會在不浪費內存的情況下爲您提供信息。 –