I searched and tested for a while and just canβt find that what I am trying to accomplish is perhaps how I am doing it.
I would like to add a key / value pair to an array when defining an array based on a three-dimensional statement.
Array( 'Item 1' => 'Some value', (FALSE)? NULL : 'Item 2' => 'Another Value' )
Expected / desired behavior for the result:
Array ( [Item 1] => Some value [Item 2] => Another Value )
And when the statement is true:
Array( 'Item 1' => 'Some value', (TRUE)? NULL : 'Item 2' => 'Another Value' )
Output:
Array ( [Item 1] => Some value )
But instead, I get:
Array ( [Item 1] => Some value [] => Another Value )
Which causes problems, since A) I do not want this second element to exist in the first place, and B) The False value of the condition is assigned to the value of the True condition (in this case NULL, which sets the key to NULL [])
It is very strange. Is my only option is to have the standard if () {} operator and call the element if this condition is false (using!) In an array?
Note. The presence of a null value for element 2 is unacceptable, but if the initial condition is true, no element should exist at all.
Any help would be greatly appreciated!
source share