- file_get_contents: documentation ( source)
- array_intersect_assoc: documentation ( source)
- json_decode: documentation ( source)
- print_r: documentation ( source)
- array_filter: documentation ( source)
<?php
$json = file_get_contents('https://my.tradebuilders.com.au/Ajax/Members/?GetSupplierInfo=Yes');
$array = json_decode($json, true);
$array = array_filter($array, function (array $values) {
return recursive_assoc_in_array($values, ['S' => 6026]);
});
print_r($json);
function recursive_assoc_in_array(array $haystack, array $needle, $childKey = 'ChildCats') {
if (array_intersect_assoc($haystack, $needle)) {
return true;
}
if (!isset($haystack[$childKey]) || !is_array($haystack[$childKey])) {
return false;
}
foreach ($haystack[$childKey] as $child) {
if (recursive_assoc_in_array($child, $needle, $childkey)) {
return true;
}
}
return false;
}