note 110841 added to function.uasort

From: Date: Thu, 13 Dec 2012 19:54:08 +0000
Subject: note 110841 added to function.uasort
Groups: php.notes 
Request: Send a blank email to php-notes+get-192517@lists.php.net to get a copy of this message
This code is really taking me along time to put it. I'm an amateur on arrays specially multi-dimensional one (T.T) but thanks to all others in here and there, I finally able to put this code together. So, I hope this little code can help solve your problem too as many others had helped me. <?php /********************************************* * This code is Sorting on * multi-dimensional array with uasort() * $data is 4 Dimensional Array * *********************************************/ $data = array( array( 'attributes' => array( array('name' => 'Micrologic', 'age' => '2.0'), array('name' => 'Pole', 'age' => '4P') ), 'ref' => '33463E', 'price' => '5.500' ), array( 'attributes' => array( array('name' => 'Micrologic', 'age' => '2.0'), array('name' => 'Pole', 'age' => '3P') ), 'ref' => '33460E', 'price' => '7.500' ), array( 'attributes' => array( array('name' => 'Micrologic', 'age' => '5.0'), array('name' => 'Pole', 'age' => '4P') ), 'ref' => '33549E', 'price' => '2.500' ), array( 'attributes' => array( array('name' => 'Micrologic', 'age' => '5.0'), array('name' => 'Pole', 'age' => '3P') ), 'ref' => '33546E', 'price' => '7.500' ) ); /*** uasort function ***/ function compareRef($a, $b){ return strnatcmp($a['ref'],$b['ref']); } uasort($data, 'compareRef'); /*** Print $data ***/ echo "--SORT BY REF-- <br />"; foreach($data as $idx => $prod) { foreach($prod['attributes'] as $attrib) echo $attrib['name'].' - '.$attrib['age'].", "; echo " = ".$prod['ref']." & Rp.".$prod['price']."<br />"; } ?> (^^)b ---- Server IP: 69.147.83.199 Probable Submitter: 180.243.78.106 ---- Manual Page -- http://php.net/manual/en/function.uasort.php Edit -- https://master.php.net/note/edit/110841 Del: integrated -- https://master.php.net/note/delete/110841/integrated Del: useless -- https://master.php.net/note/delete/110841/useless Del: bad code -- https://master.php.net/note/delete/110841/bad+code Del: spam -- https://master.php.net/note/delete/110841/spam Del: non-english -- https://master.php.net/note/delete/110841/non-english Del: in docs -- https://master.php.net/note/delete/110841/in+docs Del: other reasons-- https://master.php.net/note/delete/110841 Reject -- https://master.php.net/note/reject/110841 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#192517) next »