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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because it is a ternary operator. This code:
is equivalent to:
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: