note 33419 deleted from function.array-multisort by aidan

From: Date: Sun, 03 Oct 2004 10:44:59 +0000
Subject: note 33419 deleted from function.array-multisort by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-77795@lists.php.net to get a copy of this message
Note Submitter: adriano_allora at mac dot com ---- How to order a multidimensional array without writing each key of its. I had a multi-array like this: <?php $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: <?php 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

« previous php.notes (#77795) next »