Home > Software design >  PHP API wont return right data
PHP API wont return right data

Time:12-03

So im using the spaceX api to try and understand retrieving data using php a bit more,

my base url is : enter image description here

from here i want the webcast link, but i cannot acces it somehow.

my current code:

$api_url = 'https://api.spacexdata.com/v5/launches/';

$json_data = file_get_contents($api_url);


$data = json_decode($json_data, true);
//var_dump($data);
$i = 0;
foreach ( $data as $launches)
{
    $i  ;
    if($i > 2) break;
    var_dump($launches["fairings"],
            $launches["links"], '<br/>');
}

that returns: enter image description here

how can i return the 'webcast' url

CodePudding user response:

$launches["links"]["webcast"]

You can chain your properties to go down the objects/arrays values... This is the same as doing

$links = $launches["links"];
$links["webcast"];
  • Related