note 33419 added to function.array-multisort

From: Date: Wed, 25 Jun 2003 12:42:29 +0000
Subject: note 33419 added to function.array-multisort
Groups: php.notes 
Request: Send a blank email to php-notes+get-50988@lists.php.net to get a copy of this message
How to order a multidimensional array without writing each key of its. I had a multi-array like this: $mega-array = array('sub-arr1' => array( 'url' => 'http://www.e-allora.net/ompeig.php', 'point1' => '20', 'point2' => '11', 'point3' => '3'), 'sub-arr2' => array( 'url' => 'http://www.fixproject.org', 'point1' => '5', 'point2' => '3', 'point3' => '7'); ...and I want to order its elements (links in a mainpage) by different point-value (more point before, less point after) in different menues (one for "point1", another one for "point3", another one for "point2"). I wrote this function: function byPoint($array,$param) # where the value of $param could be point(1|2|3), but you can name with # other names your categories # byPoint($array,"point1"); { while($var1 = each($array)) { $actual_key = $var1['key']; $actual_value = $array[$actual_key][$param]; $array_1[$actual_key] = $actual_value; } reset($array); arsort($array_1); $x = 0; while($new_value = each($array_1)) { $new_key = $new_value['key']; $url = $array[$new_key]['url']; $x++; if($x < 6) { echo "<a href=\"$url\" class=\"main\">"; echo "$chiave</a>&middot;\n"; } } reset($array); } Shar&njoy ---- Manual Page -- http://www.php.net/manual/en/function.array-multisort.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33419 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33419&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33419&report=yes

« previous php.notes (#50988) next »