There are perfectly suitable approaches detailed here, but considering the actual structure of your array, this probably requires a bit more explanation. Specifically, here's how you can sort by both keys and values:
uksort($array, function ($siteA, $siteB) use ($array) {
$priceA = $array[$siteA]['price'];
$priceB = $array[$siteB]['price'];
if ($priceA == $priceB) {
return strcmp($siteA, $siteB);
}
if (!$priceB) {
return -1;
}
if (!$priceA) {
return 1;
}
return $priceB - $priceA;
});
You might need to adjust the specific comparisons and return logic here, but this illustrates the approach.