繁体   English   中英

如何检查返回的值是否为null?

[英]How can I check if the value returned is null?

下面的代码有效,我能够获得汽车的颜色。 现在,当该网站是专业制作的时,某些字段尚未填写。 因此,某些字段要么为0,要么为空,为空或为空。 我感兴趣的是颜色列。 一些字段为空。

Function getCarColor($cariD){
  the rest of my sql code
  $carColor = $ref['color'];
  return $carColor;
}

我陷入的问题是如何检查它们是否为空,并在其中添加随机文本,以确保一切看起来统一。

这是我的代码

Function getCarColor($cariD){
  the rest of my sql code
  $carColorchk = $ref['color'];
  $carColor == is_null (('unspecified') ?: $carColorchk);
  return $carColor;
}

请帮忙。 我将在圣诞节晚餐时以你的名义多吃一些玉米粉蒸肉。

有很多方法可以做到这一点。 您可以尝试以下方法:

<?php
    if((!empty($your_value)) && ($your_value ! =0) && ($your_value !='')){
        //your Code
    }
?>

尝试:

如果使用的是php 7,则可以使用null合并运算符:

$carColor = $ref['color'] ?? 'nocolor';

或以下用户(如果仅php> = 5.3)

$carColor = $ref['color'] ?: 'nocolor';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM