When dealing with php array we sometimes needs sorting functionality.if we want to sort an array based on a key in php here is the function which helps you to do so.

<?php
function subval_sort($array,$subkey,$sr) 
{
	
	foreach($array as $k=>$v) {
		$b[$k] = strtolower($v[$subkey]);
	}
	if($sr=='asc'){
	asort($b);}
	else{arsort($b);}
	foreach($b as $key=>$val) {
		$c[] = $a[$key];
}
	return $c;
}
?>

here,
$array is the array to be sorted.
$subkey is the key.
$sr is the order asc or desc.

Leave a Reply

Your email address will not be published. Required fields are marked *