$response = json_decode(file_get_contents($url), true);
print_r(array_keys($response));
gives:
Array ( [0] => country [1] => result_count [2] => longitude [3] => area_name [4] => listing [5] => street [6] => town [7] => latitude [8] => county [9] => bounding_box [10] => postcode )
print_r($response) ;
gives:
Array ( [country] => England [result_count] => 1796 [longitude] => -1.210158 [area_name] => Oxford [listing] => Array ( [0] => Array ( [country_code] => gb [num_floors] => 0 [image_150_113_url] => https://lid.zoocdn.com/150/113/d23e28cf074d77c62ec7151dab09cffa8dbaf210.jpg [listing_status] => sale [num_bedrooms] => 6 [location_is_approximate] => 0 [image_50_38_url] => https://lid.zoocdn.com/50/38/d23e28cf074d77c62ec7151dab09cffa8dbaf210.jpg [latitude] => 51.74293 [furnished_state] => [agent_address] => High Street, Goring, Reading [category] => Residential [property_type] => Detached house [longitude] => -1.313658 [thumbnail_url] => https://lid.zoocdn.com/80/60/d23e28cf074d77c62ec7151dab09cffa8dbaf210.jpg [description] => Nestled in a private corner of exclusive Hid’s Copse Road on the outskirts of Oxford, Water Combe is a brand new property constructed to an extraordinarily high standard with an astonishing attention to detail. The property is full of light and space with most rooms having a double aspect and large windows designed to take advantage of the far reaching and garden views. Bespoke features include a luxurious designer kitchen/breakfast room, generous reception rooms, spacious hallways and landings, an internal green oak frame which adds stunning character, wide oak floors, large bedrooms and fabulous bathrooms with Bateau bath tubs.Set within 1.2 acres, the landscaping has been designed around the Fairy Glen at the bottom of the garden and the Fairy theme continues throughout the house and garden. This enchanting home has had no expense spared to create a unique home for the discerning buyer. Awaiting EPC Rating.Local informationCumnor Hill is a sought after residential area just 1.5 miles from the centre of Oxford. It is well served by communications with access to the A34 and Oxford ring road, connecting to the M4 and M40 motorways, with the regional centres of Newbury and Swindon also within easy reach.Communications by rail are also excellent with fast trains from either Oxford or Didcot to London Paddington taking about 50 and 45 minutes respectively. From the coach station at Gloucester Green there are regular services to London Heathrow and Gatwick airports.Hid’s Copse
If you want to have functions like that available everyone in your app, the best way is to create a helpers file and autoload it.
// create a helpers.php file under /app for example
function array_keys_multi(array $array)
{
$keys = array();
foreach ($array as $key => $value) {
$keys[] = $key;
if (is_array($array[$key])) {
$keys = array_merge($keys, array_keys_multi($array[$key]));
}
}
return $keys;
}
// update your composer.php with:
"autoload": {
"psr-4": {...},
"classmap": [...],
"files": ["app/helpers.php"] //add this line
},
// anywhere you need to call the function
array_keys_multi($myArray)
Another option is simply to create a method in the current class and call it