PHP - Get bool to echo false when false

前端 未结 14 1873
予麋鹿
予麋鹿 2020-11-22 14:09

The following code doesn\'t print out anything:

$bool_val = (bool)false;
echo $bool_val;

But the following code prints 1:

14条回答
  •  轮回少年
    2020-11-22 14:44

    json_encode will do it out-of-the-box, but it's not pretty (indented, etc):

    echo json_encode(array('whatever' => TRUE, 'somethingelse' => FALSE));
    

    ...gives...

    {"whatever":true,"somethingelse":false}
    

提交回复
热议问题