Is there a way to shorten this?
<?php if (($_SESSION['Particulos'] == "L")OR($_SESSION['Particulos'] == "E")) { } ?>
To something like this:
<?php if ($_SESSION['Particulos'] == "L" OR "E") { } ?>
Or do I have to always write the $Session?
I have been looking at the PHP page but the examples are not clear to me.
<?php if( strpos("LE", $_SESSION['Particulos']) !== false ) { } ?>
strpos
looks for the position in thestring
"LE" where the value of the variable is found$_SESSION
, if it is not it returnsfalse
.Another shorter one, using regular expression:
<?php if( preg_match("(L|E)", $_SESSION['Particulos']) ) { } ?>
Well almost. LOL.
With array:
<?php if( in_array( $_SESSION['Particulos'], ['L','E']) ) { } ?>
Other:
<?php if( strpos("=LE", $_SESSION['Particulos']) ) { } ?>
That's the shortest way I know! Cheers
This method is impossible because at the moment of calling the declaration
OR
we are "restarting" the request for what we are looking for!. It means that in this case "E" would remain null or invalid.or with
switch
review: http://php.net/manual/en/control-structures.switch.php