-1
如何直接在PHP中添加其他數組?將新數組添加到現有值並保存回數據庫
比如我有兩個項目在數組
Array(
[1] => Fruits
[2] => Books
)
假設我的數據。我有一個叫做家
房子包含2個數據是水果和書籍的數組。
現在我想添加顏色水果和書籍與另一個陣列。
我不喜歡這樣的:
$house = $this->config->get("house"); //now I get the main array contains Fruits and Books
foreach($house as $house_content => value) // get the value for each eg. Fruits, Books
if(!is_array($value)){ //check whether Fruits is an array cause I wanna add array of color into it
$house[$house_content][red] = $value; // can I do like this to make it create another array name [red] under the Fruits or Books?
}
我沒有這樣做。我應該怎麼做呢[水果] [紅色],而他們原本[水果]只?