I would like to initialize an array:
$arr = array(
"date_edited" => time(),
"date_added" => ($action == "add" ? time() : NULL)
...
);
I use this array to update a database table.
Note the 2nd key, date_added. What I would like “date_added” not to be included in the array if $action is not “add”. So in this case ($action != “add”), isset($arr[‘date_added’]) should be false.
Is it possible right at the array’s initialization? (I tried with NULL, but didn’t work)
You can keep using your method and just filter it on declaration:
Example:
Will output: