2

I have some JSON data here http://pastebin.com/5VeJ5dda

How do I access ipaDownloadUrl on each case and put them in two variables in PHP? I already did

<?php
$api = url_get_contents("http://example.com/api");
$decoded_api = json_decode($api);

?>

Now can you help me what to do next to get the specified elements?

1 Answers1

1

You can access it like that:

<?php
$api = url_get_contents("http://example.com/api");
$decoded_api = json_decode($api);

echo $decoded_api['InfiniteApp']['ipaDownloadUrl'];

?>
Imphusius
  • 648
  • 5
  • 15
  • You didn't even read my question, neither the JSON data – Jakeashacks Jan 02 '17 at 17:12
  • @Jakeashacks I read your question, and understood it just as Imphusius did. Perhaps you're being unclear? – ceejayoz Jan 02 '17 at 17:13
  • You didn't see there are two ipaDownloadUrl? I want each of them in two separate variables – Jakeashacks Jan 02 '17 at 17:14
  • @Jakeashacks Then use `print_r` to understand the structure. `$decoded_api['InfiniteApp']` appears to be an array. Step through them with a for/foreach loop. – ceejayoz Jan 02 '17 at 17:16
  • I know in javascript I can do this: `data.InfiniteApp[0].ipaDownloadUrl` and `data.InfiniteApp[1].ipaDownloadUrl`. This is what I want to do in PHP – Jakeashacks Jan 02 '17 at 17:16
  • @Jakeashacks That's entirely doable in PHP. http://php.net/manual/en/language.types.array.php – ceejayoz Jan 02 '17 at 17:35
  • OK, I got someone to answer me. It was so simple. `$decoded_api->data->InfiniteApp[0]->ipaDownloadUrl`. Anyone here couldn't answer. Hah – Jakeashacks Jan 03 '17 at 11:13