Paul
Paul

Reputation: 431

PHP Multi Dimensional Array's Value?

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.

Upvotes: 0

Views: 52

Answers (1)

sectus
sectus

Reputation: 15464

  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';
    }
    

Upvotes: 1

Related Questions