//php
$a=array(array("id" => 4,"name"=> "Dog"),array("id" => 1,"name"=> "Cat"),array("id" => 3,"name"=> "Hourse"),array("id" => 2,"name"=> "Bear"),array("id" => 5,"name"=> "Zebra"));
$b = array_column($a,'name'); // which column needed to be sorted
array_multisort($b,SORT_ASC,$a); // sorts the array $a with respective of aray $b
$price = array_column($inventory, 'price');
array_multisort($price, SORT_DESC, $inventory);
//php 7+
usort($inventory, function ($item1, $item2) {
return $item1['price'] <=> $item2['price'];
});
$price = array();
foreach ($inventory as $key => $row)
{
$price[$key] = $row['price'];
}
array_multisort($price, SORT_DESC, $inventory);
// take an array with some elements
$array = array('a','z','c','b');
// get the size of array
$count = count($array);
echo "<pre>";
// Print array elements before sorting
print_r($array);
for ($i = 0; $i < $count; $i++) {
for ($j = $i + 1; $j < $count; $j++) {
if ($array[$i] > $array[$j]) {
$temp = $array[$i];
$array[$i] = $array[$j];
$array[$j] = $temp;
}
}
}
echo "Sorted Array:" . "<br/>";
print_r($array);