所以我有一个数组名为$销售对象是consits像:添加键和值数组,如果它不存在
"DR22" => array:3 [▼
"brand" => "DR22"
"year" => "0"
"last_year" => null
]
"FGIPA46C" => array:3 [▼
"brand" => "FGIPA46C"
"month" => "3"
"year" => "3"
]
现在,每个人都应该有“月”“年”“去年”“上个月“,但如果没有销售它不在那里,我得到,但如果它不存在,我只想添加0值。我试过:
foreach ($sales as $sale)
{
if (empty($sale['month'])) {
$sale['month'] = 0;
}
}
但它没有添加任何东西。吐出同样的东西。
'的foreach($销售为&$销售)'请参阅'&'? –
http://php.net/manual/en/language.references.pass.php我在我的求职者测试中使用 – nogad
他的意思是我不会把'$ sale ['month']'添加到退出的数组@ RomanPerekhrest – nogad