Broken php array indexing -
there must obvious i'm doing wrong here, i've spent hours trying figure out , makes no sense.
<?php date_default_timezone_set('america/new_york'); $json = file_get_contents('https://www.govtrack.us/api/v2/vote/?congress=114&chamber=house&session=2015&order_by=-created'); $obj = json_decode( $json,true); $bills = $obj['objects']; foreach($bills $b){ print_r($b); print_r($b['category']); print_r($b['title']); ///wtf. } ?> the array returned json request has indices both category , title, returns null title. several other elements json array return null reason. php returns undefined index error, index defined.
what missing here?
the title index under related_bill, not main objects array.
this should work:
foreach($bills $b){ print_r($b); print_r($b['category']); print_r($b['related_bill']['title']); }
Comments
Post a Comment