0

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 Answer 1

1
  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';
    }
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.