I would like to a simple if shorthand that check if an array has a particular key and if so unset it.
$test = array("hi" => "123");
isset($test["hi"]) ? unset($test["hi"]);
Why does this give a parse error? What is the correct syntax.
I would like to a simple if shorthand that check if an array has a particular key and if so unset it.
$test = array("hi" => "123");
isset($test["hi"]) ? unset($test["hi"]);
Why does this give a parse error? What is the correct syntax.
Because it is a ternary operator. This code:
$a = ($condition)? $b : $c;
is equivalent to:
if($condition) $a = $b;
else $a = $c;
For what you ask, there is no need for a check, you can simply unset()
the array element without first checking it, and it would give no error messages:
unset($test["hi"]);