Innovations DesignInnovations Design

  Tech Stuff > Downloads > * array_rows_to_columns  
 
array_rows_to_columns

This is a module to simplify the sorting of arrays. Sorting a multi-dimensional array by multiple key fields isn't something that you need to write that frequently. As a result, you can waste quite a bit of time figuring out how to make it work (I know I did!). Having spent the better part of a day working through this (experimenting with different options), I didn't want to ever have to do that again. I wrote this module to make it easy to do it the next time. I share it here so you can avoid wasting this time as well.

Using it looks like this:

 array_rows_to_columns ($test,"last_name","first_name","address","phone"); 
 $result = array_multisort($sort_field1,$sort_field2,$sort_field3,$sort_field4,$test);  

The array_multisort is standard PHP so the key is the setup to make it work. The array_rows_to_columns uses the approach suggested in the PHP help file to turn the individual fields into separate arrays so they all become sortable. Through the magic of PHP's associative arrays, the sort then works and all the associations remain intact.

The downloadable file includes a demo module.

Download it here



 
Top!
© Innovations Design Powered by Website Baker
Template Modified by Chris Shea - Adapted by P. Mathijssen - Original design by Mamboteam.com!
Top!

@MEMBER OF PROJECT HONEY POT
Spam Harvester Protection Network
provided by Unspam