Answers for "bool to text in php"

PHP
0

boolean to string php

echo json_encode(true);  // string "true"

echo json_encode(false); // string "false"

// null !== false
echo json_encode(null);  // string "null"
Posted by: Guest on November-24-2021
1

php convert string to boolean

/**
 * Strings always evaluate to boolean true unless they have a
 * value that's considered "empty" by PHP (taken from the
 * documentation for empty):
 * "" (an empty string) evaluates as false.
 * "0" (0 as a string) evaulates as false.
 * If you need to set a boolean based on the text value of a
 * string, then you'll need to check for the presence or
 * otherwise of that value.
 */
$boolean = $string === 'true' ? true: false;
Posted by: Guest on April-09-2020

Browse Popular Code Answers by Language