So im using the spaceX api to try and understand retrieving data using php a bit more,
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/>');
}
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"];