I have this code:
...............................................
'Detalle' => array()
];
foreach ($cart as $line => $item) {
//check condition
if (strtolower($item['description']) === 'something') {
$cond = true;
} else {
$cond= false;
}
$ab['Detalle'][]=array(
'NmbItem' => $item['name'],
'QtyItem' => (int)$item['quantity'],
'PrcItem' => $item['price']
);
if ($cond){
$array2 = array('IndExe' => 1);
array_merge($ab['Detalle'],$array2);
}
}
How can I add 'IndExe' to $ab['Detalle'] array only when the condition is true? I tried array_merge, array_merge_recursive but nothing.
IndExe only can be 1, another value like 0 or null is not possible. I tried:
$ab['Detalle'][]=array(
'NmbItem' => $item['name'],
'QtyItem' => (int)$item['quantity'],
'PrcItem' => $item['price']
'IndExe' => ($cond? 1 : 0 )
);
but when cond = false then IndExe = 0, is not what I need. IndExe must be added only when cond = true.