Using Array_multisort to re-order data


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. $rows=$result->fetchAll(PDO::FETCH_ASSOC);
  2. $row2=$rows;
  3. $rSpec=array(); // create the key arrays
  4. $rDecl=array();
  5. $rDecl1=array();
  6. $rProp=array();
  7. foreach($rows as $r)
  8. {
  9. $rProp[]=$r['properties'];
  10. $rSpec[]=$r['specificity'];
  11. $rDecl[]=$r['declaration'];
  12. $rDecl1[]=$r['declaration'];
  13. }
  14. array_multisort($rSpec,SORT_NUMERIC,$rDecl,$rows);
  15. FunctionToWriteReport('CSS Rules by Specificty',$rows);
  16. array_multisort($rDecl1,$rProp,$row2);
  17. FunctionToWriteReport('Rules by Declaration',$rows);

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.