如何在特定键下将元素添加到我的数组中?
这是我使用 foreach 之前的数组输出。如您所见,错误字段为空。我想填写。
Array (
[0] => Array (
[transactionid] => 2223
[created] => 26-02-13 14:07:00
[cardid] => 10102609
[pricebefordiscount] => 68900
[error] =>
)
这是我的前锋。如您所见,我已经尝试通过实施来完成这项工作$arrayname['index'] = $value;
。但这不起作用,当我吐出print_r
. 为什么会这样?
foreach ($samlet as $key)
{
if ($key['pricebefordiscount'] > '200000')
{
$samlet['error'] = "O/2000";
}
if ($key['cardid'] === '88888888')
{
$samlet['error'] = "Testscan";
}
}
这是所需的输出:
Array (
[0] => Array (
[transactionid] => 2223
[created] => 26-02-13 14:07:00
[cardid] => 10102609
[pricebefordiscount] => 68900
[error] => "Testscan"
)