0

I already know what is_int() is used for. But I only know that to print the result of this function we need to use the var_dump() function. So can someone explain to me why echo, print or print_r() cannot display is_int()?

$var1 = '123';
var_dump(is_int($var1)); // return False;

$var2 = '123';
echo/print/print_r($var2); // Not working
Quốc Cường
  • 417
  • 4
  • 12
  • Take a look at this, apparently, it's how PHP is designed, `false` value is automatically converted to blank when you echo it out. https://stackoverflow.com/questions/4948663/php-get-bool-to-echo-false-when-false – catcon Jul 13 '19 at 03:42

1 Answers1

0

In PHP (boolean) false will be converted to "" (empty string) and boolean (true) will be converted to 1 so when you print_r and the return value is false then you will get the empty string. So either use the var_dump to get the variable details where it will give you the type and value both.

Here is the way to echo the true and false based on the result. you can use this too

$var1 = '123';
echo is_int($var1)?'true':'false';
Ashok Gadri
  • 520
  • 4
  • 11