Welcome Guest, Not a member yet? Register   Sign In
PHP boolean value assignment
#1

[eluser]Madmartigan1[/eluser]
I see a lot of people doing this:

Code:
if ($foo === $bar)
{
     $baz = true;
}
else
{
     $baz = false;
}

or...

Code:
$baz = $foo === $bar ? : true : false;

Am I missing something?
Isn't this exactly the same, in every case, as this?
Code:
$baz = $foo === $bar;
#2

[eluser]WanWizard[/eluser]
Yes, it is.

Try only difference is the readability, which reduces are you go down the list of your examples...
#3

[eluser]Ochetski[/eluser]
Its not common to people use a comparison as value to a variable, that's the reason.
#4

[eluser]pkrstic[/eluser]
Most of them don't know for last solution. Personaly I use it a lot, for simple expressions this is easier to read than first and second solution.

Also this can be used for any kind of comparsion when you need boolean as result.




Theme © iAndrew 2016 - Forum software by © MyBB