You are here: Re: [PHP] syntax for two comparison operators « PHP « IT news, forums, messages
Re: [PHP] syntax for two comparison operators

Posted by Philip Hallstrom on 08/25/05 04:38

> Is there a technical reason why PHP does not allow comparison operator
> expressions like the following:
>
> if (2 < $x <= 4) {}
>
>
> I prefer this concise way as it is common for mathematics expressions, and
> much easier to grasp physically on first glance. From what I can tell, this
> expression can currently only be written as:
>
> if ( $x > 2 && $x <= 4) {}

I'm sure someone who knows more about it than me will chime in with the
real reason, but at first glance how would the interpreter interpret it?

Given 2 < $x <= 4, do you mean:

2 < $x && $x <= 4

or do you mean

(2 < $x) <= 4

where 2 < $x will evaluate to true or false. Doesn't make much sense as a
condition, but it's there...

Also, you could wrap it in a function if you find you use it a lot..

function between($x, $min, $max) {
return( $min < $x && $x < $max );
}

-philip

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация