Home >Backend Development >PHP Tutorial >PHP method to implement array sorting by specified KEY, PHP array key sorting_PHP tutorial
This article describes the example of php method to implement array sorting by specified KEY. Share it with everyone for your reference. The specific implementation method is as follows:
function array_sort($arr,$keys,$orderby='asc'){ $keysvalue = $new_array = array(); foreach ($arr as $k=>$v){ $keysvalue[$k] = $v[$keys]; } if($orderby== 'asc'){ asort($keysvalue); }else{ arsort($keysvalue); } reset($keysvalue); foreach ($keysvalue as $k=>$v){ $new_array[] = $arr[$k]; } return $new_array; }
I hope this article will be helpful to everyone’s PHP programming design.