Whats the syntax for multiple ===

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Whats the syntax for multiple ===

Post by Shendemiar »

Code: Select all

if($s0 === $s1 === $s2 === $s3 === $s4 === $s5 === $s6 === $s7 === $s8 === $s9 === $s10)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Image
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

The line gives error!

Code: Select all

Parse error: parse error, unexpected T_IS_IDENTICAL
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What's the logic you're trying to accomplish, in plain words, not code?
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

feyd wrote:What's the logic you're trying to accomplish, in plain words, not code?
To see if they are all the same.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

if ($s0 === $s1 and $s1 === $s2 ...)
would be one possible route.

If they are all truely named as such, there is an algorithmic way as well using variable variables.
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

All the $s are equal strings...


How come

Code: Select all

echo var_export((((((((((($s0 == $s1) == $s2) == $s3) == $s4) == $s5) == $s6) == $s7) == $s8) == $s9) == $s10));
Gives True

While

Code: Select all

echo var_export((((((((((($s0 === $s1) === $s2) === $s3) === $s4) === $s5) === $s6) === $s7) === $s8) === $s9) === $s10));
Gives false


In my logic they both should give false, since ($s1==$s2) == true, and (true==$s3)==false

And without the ((((( )))))'s they should both give true, but they give error.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$s0 === $s1 returns a boolean type. Since none of the other $s* are boolean, they would immediately fail the identical check.
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

That explains the later, but how come the first one returns true?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

a nonempty string compared to a boolean true returns true.

The code doesn't work the way you are wishing it to.
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

Ok, thanks, time tomove on. :D
Post Reply