php boolean help

半腔热情 提交于 2020-03-27 03:58:17

问题


I seem to have a small problem, in the code below $a_trip is always true, even if $trip!= $admin_trip. Any idea why?

if($trip == $admin_trip)
$a_trip = true;


if($a_trip == true)
$trip = ("~::##Admin##::~");

回答1:


In PHP, strings and numbers other than zero will evaluate as true. Make sure that $a_trip is false or empty, or use the equality operator that evaluates type:

if($a_trip === true)



回答2:


PHP's normal equality is very lax, and considers many values to be the same even when types are different.




回答3:


Beat me to it. === means 'identical'.

Check this out.

http://php.net/manual/en/language.operators.comparison.php

Also a sidenote, you should use { } in your if statements. You'll thank yourself later when debugging. It's easier to read.



来源:https://stackoverflow.com/questions/2485506/php-boolean-help

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!