如何推动价值,通过索引spesific在php中?



我有对象的数据数组。在这里:

Array
(
[0] => Array
(
[name] => Soil 
[method] => 
)
[1] => Array
(
[name] => 10 mm 
[method] => 
)
)

这里我接收输入索引和值。

$index = 1;
$method = 'junior' 

我想根据我收到的索引数据推送数据

结果

Array
(
[0] => Array
(
[name] => Soil 
[method] => 
)

[1] => Array
(
[nama_barang] => 10 mm 
[method] => junior // push by index 1
)
)

如何?由于

$yourArray[1]['method'] = 'junior'

在PHP中,您只需将值赋给数组。如果路径键不存在,则自动创建。