Jump to content

$blah = ($foo) ? $bar : $help


conker87

Recommended Posts

I've been looking into this alternative way of doing if statements.

 

I'm still a little confused as to how and where I can use it. For instance, can I use it like this:

 

echo ($foo) ? "bar" : "not bar";

Or will I have to do it like this:

$test = ($foo) ? "bar" : "not bar"; echo $test;

Link to comment
https://forums.phpfreaks.com/topic/100649-blah-foo-bar-help/
Share on other sites

You can use the first one. You can think of it like this: PHP first goes over the ?: bit and then executes the function or whatever. So

echo ($foo) ? "bar" : "not bar";

is really either

echo "bar";

or

echo "not bar";

 

You can put it anywhere where "bar"/"not bar" is expected.

 

Geddit?

Link to comment
https://forums.phpfreaks.com/topic/100649-blah-foo-bar-help/#findComment-514754
Share on other sites

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.