Complete the code to perform a loose comparison between two variables.
<?php $a = 5; $b = '5'; if ($a [1] $b) { echo "Equal"; } else { echo "Not equal"; } ?>
In PHP, == is used for loose comparison, which compares values after type juggling.
Complete the code to perform a strict comparison between two variables.
<?php $x = 10; $y = '10'; if ($x [1] $y) { echo "Identical"; } else { echo "Not identical"; } ?>
The === operator checks both value and type, so it is a strict comparison.
Fix the error in the code to correctly check if two variables are not strictly equal.
<?php $a = 0; $b = false; if ($a [1] $b) { echo "Not identical"; } else { echo "Identical"; } ?>
The !== operator checks if two variables are not identical in value or type.
Fill both blanks to create a dictionary that maps comparison operators to their descriptions.
<?php
$comparisons = [
'[1]' => 'Loose equality',
'[2]' => 'Strict equality'
];
print_r($comparisons);
?>The == operator is for loose equality, and === is for strict equality.
Fill all three blanks to complete the code that checks different comparisons and prints results.
<?php $a = '0'; $b = 0; if ($a [1] $b) { echo "Loose equal\n"; } if ($a [2] $b) { echo "Strict equal\n"; } if ($a [3] $b) { echo "Not strict equal\n"; } ?>
The first if uses == for loose equality, the second uses === for strict equality, and the third uses !== for not strict equality.