Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value 0 and 1 is equal to false and true in php

Tags:

php

some time we use 0 value or 1 value for php, instead of 0 and 1 value, can we use True/False method in php.


2 Answers

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.

https://www.php.net/manual/en/language.types.string.php#language.types.string.casting

like image 169
wind Avatar answered Dec 05 '25 03:12

wind


We converting the in boolean datatype in FALSE:

  • the boolean FALSE itself the integer 0 (zero)
  • the special type NULL (including unset variables)
  • an object with zero member variables (PHP 4 only) string "0"
  • SimpleXML objects created from empty tags
  • the empty string,and the
  • the float 0.0 (zero)
  • an array with zero elements

Every other value is considered TRUE.

like image 36
Jaydip Bhingradiya Avatar answered Dec 05 '25 03:12

Jaydip Bhingradiya