douhan1992 2012-11-04 15:23 采纳率: 100%
浏览 42
已采纳

检查两个字符串是否为空不起作用

I have a conditional if check on a webform on which ajax (and php) is doing the submit work.

if(empty($name) or empty($message))
{
do something
}

The above is working if one of the 2 strings is empty.I want to add to the above

  or (empty($name) and empty($message))

for checking if both strings are empty but in someway its not working!I want to make sure all 3 senarios are covered,Name empty or Message empty or both empty. Any ideas?

  • 写回答

3条回答 默认 最新

  • douyin4561 2012-11-04 15:25
    关注

    This will check that both $name and $message is not blank, than true

    if($name != '' &&  $message != '') {
      //Do something
    }
    

    If you use this, this will check if any 1 field is empty than the condition is true

    if($name == '' || $message == '') {
      //Do something
    }
    

    If you use this, this will be true if both are empty

    if($name == '' && $message == '') {
      //Do something
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)