0

I dont think I understand this with arrays. I have tried several methods that I found here. But I can't make it work. I understand there is a ton of this question, but I would really appreciate your help.

Can someone please help me? I want to get the URL to the image [Image] only.

Json looks like this:

{"authResponse":{"Success":true,"ErrorMessage":null},"apiCallResponse":{"Success":true,"StatusMessage":"Sign initiated","Response":{"OrderRef":"de666ed7-77ce-4da0-77a8-7777776b914b","AutoStartToken":"77cb86b3-7771-77ba-8b68-5c52e229effd","Image":"https://www.testsite.com/moretests/2f7f9152-7775-4554-7779-777777eadda"}}}

Array looks like this:

Array ( [authResponse] => Array ( [Success] => 1 [ErrorMessage] => ) [apiCallResponse] => Array ( [Success] => 1 [StatusMessage] => Sign initiated [Response] => Array ( [OrderRef] => de666ed7-77ce-4da0-77a8-7777776b914b [AutoStartToken] => 77cb86b3-7771-77ba-8b68-5c52e229effd [Image] => https://www.testsite.com/moretests/2f7f9152-7775-4554-7779-777777eadda ) ) )

Code I have tried:

$json = json_decode($response, true);
print_r($json);
echo "<br />Test: <b>".$array[4]['Image']."</b>";

//

print_r($json['Image']);

//

foreach ($json as $key => $value) {
    echo "Key: $key, value: $value";
}

//

$index = 2;
$elem = array_slice($json, $index, 1, true);
$key = key($elem);
$value = reset($elem);
echo "Key: $key, value: $value";

//

$stringItem = $json['Image'];
echo "An item by key 'Image': {$stringItem}\n";

//

if(array_key_exists("Image", $values)) {
    echo 'We have an image.';
}

1 Answers1

1

After decoding that json you will get something called multidimensional array. That means that value of some key in array can be another array. So you need to follow keys in each inner array to get to Image key.

In your example you need to do something like this:

$image = $json['apiCallResponse']['Response']['Image']
strator
  • 71
  • 1
  • 3