Answers for "php sort array by two fields"

PHP
2

sort multi array php

$keys = array_column($array, 'Price');

		array_multisort($keys, SORT_ASC, $array);
	
		print_r($array);
Posted by: Guest on August-04-2020
0

sort two diamensional array php

<?php

$data=[
  ['name'=>'Tamil',"distance"=>44],
  ['name'=>'Tamil',"distance"=>4],
  ['name'=>'Tamil',"distance"=>14],
  ['name'=>'Tamil',"distance"=>24],  
  ['name'=>'Tamil',"distance"=>10]
];
 
 for($i=0;$i<count($data);$i++)
 {
    for($j=$i;$j<count($data);$j++)
    {
        if($data[$i]['distance']>$data[$j]['distance'])
        {
            $temp=$data[$i];
            $data[$i]=$data[$j];
            $data[$j]=$temp;
        }
    }
 }
 
 print_r($data);

#tamilarasan nallairsun
Posted by: Guest on June-07-2021

Code answers related to "php sort array by two fields"

Browse Popular Code Answers by Language