开发者

Getting Unexpected '<' in simple less than greater than comparison

开发者 https://www.devze.com 2022-12-25 07:45 出处:网络
I feel very very very silly posting this, but I can\'t find the answer.I\'ve searched google and here.

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)) { 
0

精彩评论

暂无评论...
验证码 换一张
取 消