f



Newbie question #25

    $ret = json_decode(substr($result, 3), true);
    var_dump($ret);

yields:

array(4) {
  ["customerPaymentProfileIdList"]=>
  array(0) {
  }
  ["customerShippingAddressIdList"]=>
  array(0) {
  }
  ["validationDirectResponseList"]=>
  array(0) {
  }
  ["messages"]=>
  array(2) {
    ["resultCode"]=>
    string(5) "Error"
    ["message"]=>
    array(1) {
      [0]=>
      array(2) {
        ["code"]=>
        string(6) "E00039"
        ["text"]=>
        string(53) "A duplicate record already exists."
      }
    }
  }
}

How can I extract the code E00039 from $ret?

Thanks fo any help!
0
otaksoftspamtrap
11/28/2016 12:43:17 AM
comp.lang.php 32646 articles. 0 followers. Post Follow

2 Replies
173 Views

Similar Articles

[PageSpeed] 17

On 11/27/2016 7:43 PM, otaksoftspamtrap@gmail.com wrote:
>     $ret = json_decode(substr($result, 3), true);
>     var_dump($ret);
> 
> yields:
> 
> array(4) {
>   ["customerPaymentProfileIdList"]=>
>   array(0) {
>   }
>   ["customerShippingAddressIdList"]=>
>   array(0) {
>   }
>   ["validationDirectResponseList"]=>
>   array(0) {
>   }
>   ["messages"]=>
>   array(2) {
>     ["resultCode"]=>
>     string(5) "Error"
>     ["message"]=>
>     array(1) {
>       [0]=>
>       array(2) {
>         ["code"]=>
>         string(6) "E00039"
>         ["text"]=>
>         string(53) "A duplicate record already exists."
>       }
>     }
>   }
> }
> 
> How can I extract the code E00039 from $ret?
> 
> Thanks fo any help!
> 

Look at your variable.

The variable name is $ret.

It has 4 named array members:
	"customerPaymentProfileIdList"
	"customerShippingAddressIdList"
	"validationDirectResponseList"
	"messages"

From that, you have 2 named array members:
	"resultCode"
	"message"

Again, it is the latter of the two you need.

That has one array member with an index of 0.

And this has 2 named array members:
	"code"
	"text"

From which you want the first.

So the entire access would be:
   $ret["messages"]["message"][0]["code"]

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
0
Jerry
11/28/2016 2:26:31 AM
On Sunday, November 27, 2016 at 4:43:22 PM UTC-8, otaksoft...@gmail.com wrote:
> $ret = json_decode(substr($result, 3), true);
>     var_dump($ret);
> 
> yields:
> 
> array(4) {
>   ["customerPaymentProfileIdList"]=>
>   array(0) {
>   }
>   ["customerShippingAddressIdList"]=>
>   array(0) {
>   }
>   ["validationDirectResponseList"]=>
>   array(0) {
>   }
>   ["messages"]=>
>   array(2) {
>     ["resultCode"]=>
>     string(5) "Error"
>     ["message"]=>
>     array(1) {
>       [0]=>
>       array(2) {
>         ["code"]=>
>         string(6) "E00039"
>         ["text"]=>
>         string(53) "A duplicate record already exists."
>       }
>     }
>   }
> }
> 
> How can I extract the code E00039 from $ret?
> 
> Thanks fo any help!

thanks!
0
otaksoftspamtrap
11/28/2016 3:29:54 AM
Reply: