I'm trying to get some data from Wikipedia API. I found this project https://github.com/donwilson/PHP-Wikipedia-Syntax-Parser but I cannot figure out how to output the infobox entries in a loop, because the array
is in an array
which is in an array
.
The array code
[infoboxes] => Array
(
[0] => Array
(
[type] => musical artist
[type_key] => musical_artist
[contents] => Array
(
[0] => Array
(
[key] => name
[value] => George Harrison <br /><small>[[Order of the British Empire|MBE]]</small>
)
[1] => Array
(
[key] => image
[value] => George Harrison 1974 edited.jpg
)
[2] => Array
(
[key] => alt
[value] => Black-and-white shot of a moustachioed man in his early thirties with long, dark hair.
)
[3] => Array
(
[key] => caption
[value] => George Harrison at the White House in 1974.
)
)
)
)
This is what I tried (returns the value but not the key)
$values=$parsed_wiki_syntax["infoboxes"][0]["contents"];
$keys = array_keys($values);
for($i=0; $i<count($values); $i++){
foreach ($values[$keys[$i]] as $key=>$value)
echo "<b>".$key."</b>: ".$value."<br><br>";
}