Why false value in 2nd echo is not giving output 0? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 22

Why false value in 2nd echo is not giving output 0?

<?php echo 2==2; echo 2==3; ?> In first echo true outputting 1. Does it mean in php expressions evaluated to false don't output.

23rd Aug 2020, 10:41 AM
TOLUENE
TOLUENE - avatar
3 Answers
+ 4
In php, a boolean TRUE value is converted to the string "1". Boolean FALSE is converted to "" (the empty string). This allows conversion back and forth between boolean and string values. Source (php documentation)👇 https://www.php.net/manual/en/language.types.string.php
23rd Aug 2020, 10:57 AM
Arsenic
Arsenic - avatar
+ 10
Arsenic I thaught like c++ boolean false convert to 0. Thank you for your answer.
23rd Aug 2020, 10:59 AM
TOLUENE
TOLUENE - avatar
+ 2
If it is necessary to print false as integer, we can cast the evaluation result into integer echo (int)(2 == 3);
23rd Aug 2020, 11:19 AM
Ipang