PHP PHP Basics Daily Exercise Program True PHP

Alice Ng
Alice Ng
1,560 Points

Not passing this test, please help

My code seems legit. but error msg saying cant find $booleanTwo somehow. Can someone please point out where am i wrong please.

index.php
<?php
$a = 5;
$booleanOne = true;
$booleanTwo = var_dump($a==="5");
?>
Jock Perkins
Jock Perkins
8,432 Points

You have used the triple equals, which looks not only for value but type as well.

You're setting $a = 5; - which is an integer, and then looking for $a === "5" - which is a string.

Try something like :

$a = 5; $booleanOne = true; $booleanTwo = var_dump($a===5);

or

$a = "5"; $booleanOne = true; $booleanTwo = var_dump($a==="5");

1 Answer

Robert Gouveia
PRO
Robert Gouveia
Pro Student 1,713 Points

@Jock Perkins, it does not matter if he is using "" or not, because of the === it will be a true or a false regardless of the "".

That is because the boolean is not working because there is an illegal bit of code.

Try this

<?php
$a = 5;
$booleanOne = true;
$booleanTwo = $a;

if(($a === "5") === true){
  echo 'true';
} else {
  echo 'false'; 
}

var_dump($booleanTwo);
?>

Let me explain it with comments what you did wrong.

//this is fine because you have assigned a integer to a variable
$a = 5;

// this is fine because you have assigned a true state to a variable
$booleanOne = true;

//this is wrong on 2 things:
//1. you can not assign a comparable state to a variable, you need an if statement for that
//2. you can not use a var_dump function to assign on a variable.
$booleanTwo = var_dump($a==="5");

Hope this helps