Image

Imagesoltice wrote in Imagephp

Array Sorting

I have a class that stores a multidimentional (2D) array of some 3000 rows. I would like to call some function sortByColumnIndex($index)to sort the array contents by a certain column index offset. I would also like the comparison function, called by usort I imagine, to remain within the class.


class CSVtable{

   var _grid;

   ...

   function sort(){
      usort($this->_grid, array("CSVtable", "row_cmp"));
   }

   function row_cmp($a, $b){
      return strcmp($a[0], $b[0]);
   }

   ...

}



But even this times out after 30 seconds of processing. Is the table simply too big? Am I doing something wrong? And how do I carry the column index through to the compairison function?