Return to Snippet

Revision: 69275
at May 22, 2015 02:52 by COBOLdinosaur


Initial Code
$rows=$result->fetchAll(PDO::FETCH_ASSOC);
$row2=$rows;
$rSpec=array();  // create the key arrays
$rDecl=array();
$rDecl1=array();
$rProp=array();
foreach($rows as $r)
{
    $rProp[]=$r['properties'];
    $rSpec[]=$r['specificity'];
    $rDecl[]=$r['declaration'];
    $rDecl1[]=$r['declaration'];
}
array_multisort($rSpec,SORT_NUMERIC,$rDecl,$rows);
FunctionToWriteReport('CSS Rules by Specificty',$rows);
array_multisort($rDecl1,$rProp,$row2);
FunctionToWriteReport('Rules by Declaration',$rows);

Initial URL
http://coboldinosaur.com/pages/php-array-multisort.html

Initial Description
This snippet allows an array or multiple arrays to be re-sorted using multiple key fields.

Initial Title
Using Array_multisort to re-order data

Initial Tags
php

Initial Language
PHP