Re: Sorting 2D arrays

From: Date: Mon, 28 Aug 2000 20:52:46 +0000
Subject: Re: Sorting 2D arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-14003@lists.php.net to get a copy of this message
adamcharnock@btinternet.com ("Adam Charnock") writes: > Hi all. I know this is a common question and I have visited the php.net docs > about it, but how do I sort 2d arrays? I want to sort information by > $array[0][X]. How would I sort it by the values in "0" (the values are > numbers)? I have tried asort() but I haven't got the hang of it yet. The function you're after is usort: http://www.php.net/manual/html/function.usort.html function by_zeroth_element( $a, $b ) { return $a[0] < $b[0] ? -1 : $a[0] != $b[0]; } usort( $array, "by_zeroth_element" ); -- Robin Vickery............................................... Planet-Three, 3A West Point, Warple Way, London, W3 0RG, UK Email: robin@planet-three.net Phone: +44 (0)870 729 5444

« previous php.general (#14003) next »