tags:

views:

59

answers:

2

I feel very very very silly posting this, but I can't find the answer. I've searched google and here.

// originally values in a multi dimensional array, but used simple values 
// to rule out errors.
$somenumber = 1; $anotherone=5;
if ($somenumber < $res->shares < $anotherone ) {
     //blah
}

Get the error: Parse error: syntax error, unexpected '<'

Seems pretty simple and straight forward. Is there some weird thing that you can't compare multiple values? Do I have to explicitly type?

It works in Perl. Which of course means that it has to work like this in everything else. ;)

+8  A: 

Unfortunatly you can't chain comparison operators like that, you need to join them with an and (&&). See the following example:

$somenumber = 1; $anotherone=5;
if ($somenumber < $res->shares && $res->shares < $anotherone ) {
     //blah
}
Yacoby
heh... 3 seconds!
Randolpho
apparently, I have to wait 12 minutes to accept. Thanks! I soooo love PHP. Gah
Elizabeth Buckwalter
@Elizabeth: There are plenty of real reasons to hate PHP. This is not one of them.
Ignacio Vazquez-Abrams
@Ignacio Being able to chain relational operators does lead to more clarity and readability. A minor annoyance.
Yacoby
@Yacoby: PHP is so full of **major** annoyances that this is just a drop in the bucket.
Ignacio Vazquez-Abrams
@Ignacio I definitely agree with you on that point
Yacoby
It may be a minor annoyance, but there's been so many thing that were easy to muddle through like objects. This is something I had to post here. IMHO, it's more than minor. Gah again.
Elizabeth Buckwalter
+2  A: 

Chaining relational operators works in very few languages. Type out the full comparison explicitly:

if (($somenumber < $res->shares) && ($res->shares < $anotherone)) { 
Ignacio Vazquez-Abrams