-1

I have a small PHP curl script that's accessing an API URL. This is the last part of it:

    $response = curl_exec($curl);
    $err = curl_error($curl);

    $re = json_decode($response, true);
    var_dump($re);

    $item = $re['access_token'];
    var_dump($item);

This is what is contained in the $re variable dump:

    array(4) { ["auth"]=> array(4) { ["access_token"]=> string(213) "000000000000000000000" ["expires_in"]=> string(7) "2592000" ["issued"]=> string(21) "7/10/2018 11:56:41 PM" ["expires"]=> string(21) "6/11/2018 11:56:41 PM" } ["httpStatusCode"]=> int(200) ["httpStatusMessage"]=> string(11) "RESPONSE.OK" ["message"]=> string(2) "OK"}

And the dump for $item is NULL. I can't seem to grab the access_token value from within the returned array.

I've also tried this:

     $item = $re['auth'][0]['access_token'];

But it also comes up NULL.

Any ideas why this wouldn't be working?

Thanks

PassCode
  • 41
  • 6

1 Answers1

2

$re = json_decode($response, true); This line returns associative array.

So if you could try $item = $re['auth']['access_token'];

it should return the value you are looking for.