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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测