I'm new to php and API calls, I'm trying to find the email address of my local MP using the parliament API (https://members-api.parliament.uk/index.html)
Challenge is, I can't return the email address directly. I can loop through the results of the call, but I want to return the email to a variable directly. The Problem seems to be in the set of results their is a [ value. (https://members-api.parliament.uk/api/M ... 02/Contact)
I can loop through the nodes and return a value but I cant see what the node value is itself to pull out the name
Код: Выделить всё
$url = 'https://members-api.parliament.uk/api/Members/'.$ID.'/Contact';
$response = json_decode($get_data, true);
Код: Выделить всё
$email = $response["value"]["email"];
echo $email;
$ic = 0;
foreach ($response["value"] as $item) {
foreach ($item as $x){
//echo $item ;
//echo '
';
echo $item;
echo $item[$ic];
echo 'item
';
echo $x.'
';
$ic = $ic +1;
}
}
Источник: https://stackoverflow.com/questions/781 ... onse-value
Мобильная версия