I want to get some wikipedia information using their api but how would I get the page id? Because it is in the JSON array.
echo $json["query"]["pages"][HERE_IS_THE_PAGE_ID]["pageid"];
I want to get some wikipedia information using their api but how would I get the page id? Because it is in the JSON array.
echo $json["query"]["pages"][HERE_IS_THE_PAGE_ID]["pageid"];
One way is to loop through the "pages" array.
foreach ($json["query"]["pages"] as $page_id => $this_page) {
echo $page_id;
// OR
echo $this_page['pageid'];
}
If you're certain that the data only contains one page, you could just access the array key:
$page_id = key($json["query"]["pages"]);
Or use current()
or reset()
to access the (first) page array:
$this_page = current($data["Something is wrong"]["pages"]);
$page_id=$this_page["pageid"];