Using uasort() to Sort a Multdimensional Associative Array by One of Its Fields : Array sort : Data Structure PHP Source Code


PHP Source Code » Data Structure » Array sort »

 

Using uasort() to Sort a Multdimensional Associative Array by One of Its Fields






<?php
$products = arrayarrayname=>"A", price=>4.5  ),
                   arrayname=>"C", price=>5.5  ),
                   arrayname=>"D", price=>2.5  ),
                   arrayname=>"B", price=>2.5  )
);
function priceCmp$a, $b ){
   if  $a[price== $b[price] )
        return 0;
   if  $a[price< $b[price] )
         return -1;
   return 1;
}
uasort$products, priceCmp );
foreach $products as $key => $val )
     print "$key: $val[price]<BR>n";
?>


           
       



HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo Data Structure
» Array sort