I have the connection here and the query allright, but I can’t count how many of each there is in the array. Like 27 sedans, and 3 Vans and so on…
$url = 'https://gw.bilinfo.net/listingapi/api/export';
// provide your username and password here
$auth = base64_encode("demo:ocfB6XzF73");
// create HTTP context with basic auth
$context = stream_context_create([
'http' => ['header' => "Authorization: Basic $auth"]
]);
// query for data
$data = file_get_contents($url, false, $context);
// $escaped = json_encode($data);
$escaped = json_decode($data);
$iTypeGet = $escaped->Vehicles->Type;
$iTypeCount = array_count_values($iTypeGet);
//Counting how many of each element in array there are! But is not working...
foreach ($escaped->Vehicles as $vehicle) {
$temp .= "<option class='optionOne' value='" . $vehicle->Type . "'>" . $vehicle->Type . " (" . $iTypeCount . ")</option>";
}