Nuances of Shorthand Operations in PHP
Note that in shorthand operations, comparison
is performed using ==, not ===.
Without running the code, determine what will be displayed on the screen:
<?php
$test = 3;
if ($test) {
echo '+++';
} else {
echo '---';
}
?>
Without running the code, determine what will be displayed on the screen:
<?php
$test = 'abc';
if ($test) {
echo '+++';
} else {
echo '---';
}
?>
Without running the code, determine what will be displayed on the screen:
<?php
$test = '';
if ($test) {
echo '+++';
} else {
echo '---';
}
?>
Without running the code, determine what will be displayed on the screen:
<?php
$test = 3 * 'abc';
if ($test) {
echo '+++';
} else {
echo '---';
}
?>
Without running the code, determine what will be displayed on the screen:
<?php
$test = null;
if ($test) {
echo '+++';
} else {
echo '---';
}
?>
Without running the code, determine what will be displayed on the screen:
<?php
$test = false;
if ($test) {
echo '+++';
} else {
echo '---';
}
?>
Without running the code, determine what will be displayed on the screen:
<?php
$test;
if ($test) {
echo '+++';
} else {
echo '---';
}
?>
Without running the code, determine what will be displayed on the screen:
<?php
$test = 0;
if ($test) {
echo '+++';
} else {
echo '---';
}
?>
Without running the code, determine what will be displayed on the screen:
<?php
$test = '0';
if ($test) {
echo '+++';
} else {
echo '---';
}
?>
Without running the code, determine what will be displayed on the screen:
<?php
$test = -1;
if ($test) {
echo '+++';
} else {
echo '---';
}
?>