Calling https://en.wikipedia.org/w/api.php?action=query&titles=Main%20Page will return the page id:
{
"batchcomplete": "",
"query": {
"pages": {
"15580374": {
"pageid": 15580374,
"ns": 0,
"title": "Main Page"
}
}
}
}
To extract get the first object property:
$page = current((Array)$data->query->pages);
Then you have access to the page id
$pageid = @$page->pageid;