Sorting an array of sub-arrays based on a sub-array's key

From: Date: Sun, 06 Sep 2009 22:45:56 +0000
Subject: Sorting an array of sub-arrays based on a sub-array's key
Groups: php.general 
Request: Send a blank email to php-general+get-297747@lists.php.net to get a copy of this message
Hey everyone. I have an array that looks like this: $main_array[0] = array('key1' => 'vala'); $main_array[1] = array('key1' => 'valb'); etc. I want to sort the main array based on the value of key1 for each sub-array. I looked at all the array sorting functions, but unless I misunderstood something, I didn't see a direct way to do what I want. If there were a sorting function in which I could pass as an argument the name of a function that compares two elements like qsort in C, I could do it easily. Is there a function like that in PHP? If not, what should I do? Thanks everyone! James

« previous php.general (#297747) next »