您好,登錄后才能下訂單哦!
PHP中empty與false的關(guān)系是什么?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
代碼如下:
// 判斷 0 與 ''、null、empty、false 之間的關(guān)系
$a = 0;
echo "0 與 ''、 empty、null、false 之間的關(guān)系:";
if($a == ''){
echo "0 == '';";
}else{
echo "0 != '';";
}
if(trim($a) == ''){
echo "trim(0) == '';";
}else{
echo "trim(0) != '';";
}
if(strval($a) == ''){
echo "strval(0) == '';";
}else{
echo "strval(0) != '';";
}
if($a === ''){
echo "0 === '';";
}else{
echo "0 !=== '';";
}
if(empty($a)){
echo "0 is empty;";
}else{
echo "0 is not empty;";
}
if(is_null($a)){
echo "0 is null;";
}else{
echo "0 is not null;";
}
if(is_numeric($a)){
echo "0 is numeric;";
}else{
echo "0 is not numeric;";
}
if(is_string($a)){
echo "0 is string;";
}else{
echo "0 is not string;";
}
if(!$a){
echo "0 is false;";
}else{
echo "0 is not false;";
}
// 判斷 '' 和 0、null、empty、false 之間的關(guān)系
$a = '';
echo "'' 和 0、empty、null、false 之間的關(guān)系:";
if($a == 0){
echo "'' == 0;";
}else{
echo "'' != 0;";
}
if(intval($a) == 0){
echo "intval('') == 0;";
}else{
echo "intval('') != 0;";
}
if(empty($a)){
echo "'' is empty;";
}else{
echo "'' is not empty;";
}
if(is_null($a)){
echo "'' is null;";
}else{
echo "'' is not null;";
}
if(is_numeric($a)){
echo "'' is numeric;";
}else{
echo "'' is not numeric;";
}
if(is_string($a)){
echo "'' is string;";
}else{
echo "'' is not string;";
}
if(!$a){
echo "'' is false;";
}else{
echo "'' is not false;";
}
// 判斷 null 和 ''、0、empty、false 之間的關(guān)系
$a = null;
echo "null 和 ''、0、empty、false 之間的關(guān)系:";
if($a == ''){
echo "null == '';";
}else{
echo "null != '';";
}
if($a == 0){
echo "null == 0;";
}else{
echo "null != 0;";
}
if($a === ''){
echo "null === '';";
}else{
echo "null !=== '';";
}
if($a === 0){
echo "null === 0;";
}else{
echo "null !=== 0;";
}
if(strval($a) == ''){
echo "strval(null) == '';";
}else{
echo "strval(null) != '';";
}
if(intval($a) == 0){
echo "intval(null) == 0;";
}else{
echo "intval(null) != 0;";
}
if(empty($a)){
echo "null is empty;";
}else{
echo "null is not empty;";
}
if(is_numeric($a)){
echo "null is numeric;";
}else{
echo "null is not numeric;";
}
if(is_string($a)){
echo "null is string;";
}else{
echo "null is not string;";
}
if(!$a){
echo "null is false;";
}else{
echo "null is not false;";
}
echo "";
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝您對(duì)億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。