Instead of writing out
if ($var1 = $something && $var2 == $something)
echo 'this';
is it possible to write something similar to this instead
if ($var1 && $var2 == $something)
echo 'this';
Instead of writing out
if ($var1 = $something && $var2 == $something)
echo 'this';
is it possible to write something similar to this instead
if ($var1 && $var2 == $something)
echo 'this';
no, not really. There is no shortcutting operator in PHP that does what you describe, though you could write a function in PHP that saves on typing if you're doing this comparison regularly.
function allEqual($value1, $value2, $value3) {
return $value1 == $value2 && $value2 == $value3;
}
// Usage:
if( allEqual( $var1, $something, $var2 ) ) {
$a = array($var1, $var2, $something);
if(count(array_unique($a)) == 1){
// all match
}
else {
// some items do not match
}
Ref: PHP: The best way to check if 3 variables are identical?