PHP PHP Basics Daily Exercise Program True PHP

How to make this work??

Error to compare the two variables together.

index.php
<?php
$a = 5;
$isBoolean = true;
$isIdentical = '5';
$isIdentical ($a == $isIdentical);
//Place your code below this comment
?>

1 Answer

A few things here:

  1. On line 5 in your excerpt, you are missing an "=" between $isIdentical and the opening parentheses "(".
  2. The instructions for the challenge tell you to: "Compare the variable $a as equal and of the same type as the string "5" and assign the results to $isIdentical." So, we aren't just seeing if the values match - we're seeing if the TYPE of value matches (e.g. string, integer, boolean, etc).

So, we should have code that looks like this:

<?php
$a = 5;
//Place your code below this comment
$isBoolean = true;
$isIdentical = ($a === "5"); // Note how we use three equals ("===")
?>

Do you see the difference between $a (which has a value of 5) and "5"? There are no quotes around the 5 in $a, because it's an integer. The quotes around "5" tell PHP to handle it like a string. A double equal sign (==) compares the value, a triple equal sign (===) compares the TYPE of value.

Hope that helps - you were on the right track, just missing a couple equal signs :)

Thank you :)