Here is the array
$anArray = array(
\"theFirstItem\" => \"a first item\",
if(True){
\"conditionalItem\" => \"it may appear base on the condi
Try this if you have associative array with different keys:
$someArray = [
"theFirstItem" => "a first item",
] +
$condition
? [
"conditionalItem" => "it may appear base on the condition"
]
: [ /* empty array if false */
] +
[
"theLastItem" => "the last item",
];
or this if array not associative
$someArray = array_merge(
[
"a first item",
],
$condition
? [
"it may appear base on the condition"
]
: [ /* empty array if false */
],
[
"the last item",
]
);