[英]How can I add another array inside this array in php
Sorry if this title maybe seem misleading, I really didn't know how to ask this question. 抱歉,如果这个标题似乎令人误解,我真的不知道该怎么问。
So basicly I have an array like this 所以基本上我有一个像这样的数组
$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
]
]
];
I want to add another array to 'Vodka' like with values like this: 我想将另一个数组添加到“伏特加”中,像这样的值:
'Vodka'=> [
'ID' => '6',
'Name' => 'Laudur',
'Value' => '7',
'Made' => 'Acient',
'Stackable' => true
],[
'ID' => '7',
'Name' => 'Test',
'Value' => '9',
'Made' => 'New',
'Stackable' => true
]
But when I var_dump I wont get this array to 'Vodka' array, it will create [0] array. 但是当我使用var_dump时,我不会将此数组转换为'Vodka'数组,它将创建[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
How can I fix this, because I really want to add this to 'Vodka' array, but I dont want to create another 'Drinks' array? 我该如何解决此问题,因为我确实想将此添加到“伏特加”数组中,但又不想创建另一个“饮料”数组?
You need to do is:- 您需要做的是:
$array['Drinks']['Vodka']=[
$array['Drinks']['Vodka'], [
'ID' => '7',
'Name' => 'Test',
'Value' => '9',
'Made' => 'New',
'Stackable' => true
]
];
print_r($array);
Output:- https://eval.in/856440 输出: -https : //eval.in/856440
$add = [
'ID' => '7',
'Name' => 'Test',
'Value' => '9',
'Made' => 'New',
'Stackable' => true
];
$array['Drinks']['Vodka'] = array_merge([$array['Drinks']['Vodka']], [$add]);
https://eval.in/856419 https://eval.in/856419
array_merge()
http://fi2.php.net/manual/en/function.array-merge.php array_merge()
http://fi2.php.net/manual/en/function.array-merge.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.