Getting Unexpected '<' in simple less than greater than comparison
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. ;)
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
}
Chaining relational operators works in very few languages. Type out the full comparison explicitly:
if (($somenumber < $res->shares) && ($res->shares < $anotherone)) {
精彩评论