Re: How to sort a 2D array?

From: Date: Wed, 07 Mar 2001 13:35:36 +0000
Subject: Re: How to sort a 2D array?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-42909@lists.php.net to get a copy of this message
this will work <?php $array[0]['name'] = 'Chris'; $array[0]['phone'] = '3771095'; $array[0]['year'] = '1978'; $array[0]['addres'] = 'Kamloops, BC'; $array[1]['name'] = 'Breanne'; $array[1]['phone'] = '3766350'; $array[1]['year'] = '1977'; $array[1]['addres'] = 'Kamloops, BC'; $array[2]['name'] = 'Dusty'; $array[2]['phone'] = '5541120'; $array[2]['year'] = '1982'; $array[2]['addres'] = 'Kamloops, BC'; // sort by ? foreach ($array as $pos => $val) $tmp_array[$pos] = $val['year']; asort($tmp_array); // display however you want foreach ($tmp_array as $pos => $val) echo $array[$pos]['name'] ."<br>\n"; ?> -- Chris Lee Mediawaveonline.com ph. 250.377.1095 ph. 250.376.2690 fx. 250.554.1120 lee@mediawaveonline.com ""Zenith"" <zenith@linuxmail.org> wrote in message news:9844ps$qi2$1@toye.p.sourceforge.net... IF: $2D[] = array ( 'name'=>"Jacky", 'year'=>"2001", 'tel'=>"982736", 'gender'=>"Male" ); $2D[] = array ( 'name'=>"Jessica", 'year'=>"1999", 'tel'=>"349291", 'gender'=>"Felmale" ); How can I sort the array by 'name' or 'year', or other key efficiently? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#42909) next »