How can I conditionally add 'b' => 'xyz' in the array below, in the array() statement?
$arr = array('a' => abc)
The ternary operator doesn't let me do it
How can I conditionally add 'b' => 'xyz' in the array below, in the array() statement?
$arr = array('a' => abc)
The ternary operator doesn't let me do it
This is an old question, but you can accomplish this with array_merge:
array_merge(['foo' => 'bar'], $condition ? ['baz' => 'boo' ] : []);