What is the PHP best practice for using functions that return true or false?

前端 未结 5 703
面向向阳花
面向向阳花 2021-01-13 02:40

After playing with PHP, I discovered that true is returned as 1 and false as null.

echo (5 == 5) // displays 1
echo (5 == 4) // displays nothing
5条回答
  •  没有蜡笔的小新
    2021-01-13 03:26

    1. Sure. Unless you need it in a different sort of structure, e.g. a while loop.

    2. You never would. Always invert the normal function directly.

    3. When you need to differentiate false from 0, '', etc.

提交回复
热议问题