Jump to content

[SOLVED] Wtf is this? :)


Monkuar

Recommended Posts

its a short if (aka Ternary operator)

 

ie

$admin = ($name == "madtechie")?true:false;

//is the same as

if($name == "madtechie")
{
$admin = true;
}else{
$admin = false;
}


//which of couse in this case would be the same as
$admin = ($name == "madtechie");
//but you should get the idea!

 

EDIT: forgot the false! part

Link to comment
https://forums.phpfreaks.com/topic/147101-solved-wtf-is-this/#findComment-772277
Share on other sites

think of it as a oneline if

 

you know the lines

for example

<?php
if($sales > 100)
{
echo "Target Hit";
}else{
echo "Target missed";
}
?>

 

6 lines of code for what!! a hit or miss! well thats all fine and dandy.. but some times you want to type less..

 

So we get this

<?php
echo ($sales > 100)?"Target Hit":"Target missed";
?>

 

Link to comment
https://forums.phpfreaks.com/topic/147101-solved-wtf-is-this/#findComment-772290
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.