2017-09-06 147 views
1

對不起,如果這個標題可能看起來有誤導性,我真的不知道如何提出這個問題。如何添加另一個數組在這個數組中php

所以basicly我有這樣

$array= 
[ 
     'Drinks'=>[ 
       'Water'=> [ 
       'ID' => '4', 
       'Name' => 'Clean-water', 
       'Value' => '1', 
       'Made' => 'Acient', 
       'Stackable' => true 
       ], 

       'Wine'=> [ 
        'ID' => '5', 
        'Name' => 'Soff', 
        'Value' => '5', 
        'Made' => 'Acient', 
        'Stackable' => true 
       ], 

       'Vodka'=> [ 
        'ID' => '6', 
        'Name' => 'Laudur', 
        'Value' => '7', 
        'Made' => 'Acient', 
        'Stackable' => true 
       ] 



      ] 
     ]; 

數組我想另一個陣列添加到「伏特加」像這樣的價值觀:

   'Vodka'=> [ 
        'ID' => '6', 
        'Name' => 'Laudur', 
        'Value' => '7', 
        'Made' => 'Acient', 
        'Stackable' => true 
       ],[ 
        'ID' => '7', 
        'Name' => 'Test', 
        'Value' => '9', 
        'Made' => 'New', 
        'Stackable' => true 
          ] 

但是,當我的var_dump我不會得到這個數組到'伏特加'數組,它將創建[0]數組。

array (size=2) 
    'Weapons' => 
    array (size=3) 
     'Sword' => 
     array (size=5) 
      'ID' => string '1' (length=1) 
      'Name' => string 'Lurker' (length=6) 
      'Value' => string '12' (length=2) 
      'Made' => string 'Acient' (length=6) 
      'Stackable' => boolean false 
     'Shield' => 
     array (size=5) 
      'ID' => string '2' (length=1) 
      'Name' => string 'Obi' (length=3) 
      'Value' => string '22' (length=2) 
      'Made' => string 'Acient' (length=6) 
      'Stackable' => boolean false 
     'Warhammer' => 
     array (size=5) 
      'ID' => string '3' (length=1) 
      'Name' => string 'Clotch' (length=6) 
      'Value' => string '124' (length=3) 
      'Made' => string 'Acient' (length=6) 
      'Stackable' => boolean false 
    'Drinks' => 
    array (size=4) 
     'Water' => 
     array (size=5) 
      'ID' => string '4' (length=1) 
      'Name' => string 'Clean-water' (length=11) 
      'Value' => string '1' (length=1) 
      'Made' => string 'Acient' (length=6) 
      'Stackable' => boolean true 
     'Wine' => 
     array (size=5) 
      'ID' => string '5' (length=1) 
      'Name' => string 'Soff' (length=4) 
      'Value' => string '5' (length=1) 
      'Made' => string 'Acient' (length=6) 
      'Stackable' => boolean true 
     'Vodka' => 
     array (size=5) 
      'ID' => string '6' (length=1) 
      'Name' => string 'Laudur' (length=6) 
      'Value' => string '7' (length=1) 
      'Made' => string 'Acient' (length=6) 
      'Stackable' => boolean true 
     0 => 
     array (size=5) 
      'ID' => string '7' (length=1) 
      'Name' => string 'Viru' (length=4) 
      'Value' => string '8' (length=1) 
      'Made' => string 'Acient' (length=6) 
      'Stackable' => boolean true 

我怎麼能解決這個問題,因爲我真的希望它添加到「伏特加」陣列,但我不想再創建一個「飲料」陣列?

+0

是的,我看到了它。謝謝你和user3020875幫助我! – Godhaze

+0

很高興聽到這個消息 –

回答

4

你需要做的是: -

$array['Drinks']['Vodka']=[ 
       $array['Drinks']['Vodka'], [ 
       'ID' => '7', 
       'Name' => 'Test', 
       'Value' => '9', 
       'Made' => 'New', 
       'Stackable' => true 
      ] 
     ]; 

print_r($array); 

輸出: - https://eval.in/856440

相關問題