douzhuang6321 2014-10-16 09:04
浏览 16
已采纳

PHP多维数组的价值?

Ok so I am making an API call using nusoap and I get an array retuned:

Here is a sample with values if the array has data:

$result['GetOrderListResult']['Status'] VALUE: - Success
$result['GetOrderListResult']['MassageCode'] VALUE: - 0 
$result['GetOrderListResult']['ResultData'] VALUE: -  array[1]

Her is the array is there is no data:

$result['GetOrderListResult']['Status'] VALUE: - Success
$result['GetOrderListResult']['MassageCode'] VALUE: - 0 
$result['GetOrderListResult']['ResultData'] VALUE: - ''

As you can see they are very similar apart from $result['GetOrderListResult']['ResultData'] which either contains an array or doesn't. And I need to check for this but I can't seem to.

if ($result['GetOrderListResult']['ResultData'] = "") {

        $numberofresults = 'True';
    } else {
        $numberofresults = 'False';
    }

This always returns False even when the value of $result['GetOrderListResult']['ResultData'] is "" which I copy & paste from from watching the variable in xDebug.

I'm sure there is an easier method to check this, but I cannot find anything that works but I am new to PHP so apologies if this is a silly question.

  • 写回答

1条回答 默认 最新

  • doudu5498 2014-10-16 09:07
    关注
    1. You trying to assign(=) instead of compare(===).

      $result['GetOrderListResult']['ResultData'] = ""

    2. Second you API could return array() or empty string? So it's better to double check

      if (is_array($result['GetOrderListResult']['ResultData']) && count($result['GetOrderListResult']['ResultData'])) {
          $numberofresults = 'True';
      } else 
      {
          $numberofresults = 'False';
      }
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了