2013-05-12 130 views
0

我想$店數組中創建新實例添加新的數組,像這樣:PHP在二維數組

list1 = array("rose" , 1.25 , 15); 
    $list2 = array("daisy", 0.75 , 25); 
    $list3 = array("orchid", 1.15 , 7); 
    $list4 = array("orchid1", 2.15 , 9); 

    $shop = array($list1 , 
        $list2 , 
        $list3 
       ); 

//something like the line bellow 
    $shop = $shop + array(array($list4)); 
    echo $shop[3][0]; 

當我執行這個代碼,我面對這個錯誤信息:

注意:未定義偏移量:3在C:\ XAMPP \ htdocs中\ array.php上線13

線13:$店= $店+陣列(陣列($ list4));

在此先感謝^^

+0

$店[] = $ list4 – 2013-05-12 23:59:56

回答

4

如果$list4已經是一個數組,那麼你不需要array(array())。最簡單的,可能最快的方式是做:

$shop[] = $list4; 
//equivalent 
$shop[] = array("orchid1", 2.15 , 9); 
+0

這是它的TNKS好友^^ – YassineEdouiri 2013-05-13 00:01:49