Jump to content

Question about using the ternary operator


eldan88

Recommended Posts

Basically, the ternary operator is like an if ... else ... statement.

 

$array['key'] ? echo "Array key exists." : echo "Array key does not exist.";
could be written as
if($array['key'){ echo "Array key exists."; } else { echo "Array key does not exist."; }

Basically, the ternary operator is like an if ... else ... statement.

 

$array['key'] ? echo "Array key exists." : echo "Array key does not exist.";
could be written as
if($array['key'){ echo "Array key exists."; } else { echo "Array key does not exist."; }

 

Thank you for your help but i think it should be written like this  echo $array['key'] ?  "Array key exists." :  "Array key does not exist.";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.