How does php cast boolean variables?

后端 未结 3 1557
伪装坚强ぢ
伪装坚强ぢ 2021-01-15 04:31

How does php cast boolean variables?

I was trying to save a boolean value to an array:

$result[\"Users\"][\"is_login\"] = true;

but

3条回答
  •  囚心锁ツ
    2021-01-15 04:45

    Try:

    
    if((bool)$result["Users"]["is_login"] == true)
    {
        // do something
    }
    

    .

    And reply to one of your encounter:

    but when I use debug the is_login value is blank. and when I do conditionals like:

    if($result["Users"]["is_login"])

    since your return value is boolean value true, in PHP it doesn't have a representation for it, therefore appear as empty (mainwhile, if the value is a boolean false, then you'll see a 0

提交回复
热议问题