-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?
}
我没有这样做。我应该怎么做呢[水果] [红色],而他们原本[水果]只?