2013-10-04 40 views
-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? 
    } 

我沒有這樣做。我應該怎麼做呢[水果] [紅色],而他們原本[水果]只?

回答

0

你的問題實在是令人困惑

也許ü應該使用如:

$house[$house_content]['color'] = array('red','green','blue','orange'); 
0
$a=array("Fruits"=>array("red"=>"Apple","yellow"=>"Mango")); 
foreach($a as $house_content=>$values) 
{ 
    echo $values['red']; 
//print_r($house_content['red']); 
} 
相關問題