note 102234 deleted from language.operators.comparison by danbrown

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: ojrask at gmail dot leaveout dot com 

----

Hopefully this isn't something I've stupidly missed seeing from the documentation, but it seems that you can do this when comparing:

<?php
if ( $var == ( 'value1' || 'value2' || 'value3' ) )
{
    // Do stuff if $var is any of the values above.
}
?>

This would essentially be the same as:

<?php
if ( $var == 'value1' || $var == 'value2' || $var == 'value3' )
{
    // Do stuff.
}
?>

Shortens code a bit and leaves repetition out. Not sure how performance is effected.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.