Login   Register  
PHP Classes
elePHPant
Icontem

File: array_sort_example1.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Matthias Rothe  >  Advanced Array Sort  >  array_sort_example1.php  >  Download  
File: array_sort_example1.php
Role: Example script
Content type: text/plain
Description: Example of the Class in Use (readme.txt conform)
Class: Advanced Array Sort
Sorts multidimensional arrays by multiple columns
Author: By
Last change: adjusted for better output reading in html browsers
Date: 9 years ago
Size: 4,612 bytes
 

Contents

Class file image Download
<?php
function sort_array($arr$sort_string$sort_function "strcasecmp"){
  require(
"array_sort.class.inc");
  
$array_sort = new array_sort($arr$sort_string$sort_function);
  if(!
$array_sort->error["flag"]) return $array_sort->get_sorted_array();
  else return 
$arr;
  }

$test_array = array(=> array(    => "00016",
                                
=> array("tbl_txt""Allianz"),
                                
=> array("tbl_txt""DE0008404005"),
                                
=> array("tbl_txt""22"),
                                
=> array("tbl_txt""2005-04-29"),
                                
=> array("tbl_txt""91.40"),
                                
=> array("tbl_txt_pos""92.25"),
                                
=> array("tbl_txt_pos""0.93")),
                    
=> array(    => "00001",
                                
=> array("tbl_txt""Arcelor S.A."),
                                
=> array("tbl_txt""LU0140205948"),
                                
=> array("tbl_txt""187"),
                                
=> array("tbl_txt""2005-04-14"),
                                
=> array("tbl_txt""17.10"),
                                
=> array("tbl_txt_neg""15.50"),
                                
=> array("tbl_txt_neg""-9.36")),
                    
=> array(    => "00001",
                                
=> array("tbl_txt""Arcelor S.A."),
                                
=> array("tbl_txt""LU0140205948"),
                                
=> array("tbl_txt""406"),
                                
=> array("tbl_txt""2005-02-17"),
                                
=> array("tbl_txt""18.80"),
                                
=> array("tbl_txt_neg""15.50"),
                                
=> array("tbl_txt_neg""-17.55")),
                    
=> array(    => "00017",
                                
=> array("tbl_txt""BASF"),
                                
=> array("tbl_txt""DE0005151005"),
                                
=> array("tbl_txt""40"),
                                
=> array("tbl_txt""2005-04-29"),
                                
=> array("tbl_txt""49.98"),
                                
=> array("tbl_txt_pos""50.05"),
                                
=> array("tbl_txt_pos""0.14")),
                    
=> array(    => "00018",
                                
=> array("tbl_txt""EADS"),
                                
=> array("tbl_txt""NL0000235190"),
                                
=> array("tbl_txt""100"),
                                
=> array("tbl_txt""2005-04-29"),
                                
=> array("tbl_txt""22.02"),
                                
=> array("tbl_txt_pos""22.03"),
                                
=> array("tbl_txt_pos""0.05")),
                    
=> array(    => "00007",
                                
=> array("tbl_txt""Elringklinger AG NA O.N."),
                                
=> array("tbl_txt""DE0007856023"),
                                
=> array("tbl_txt""100"),
                                
=> array("tbl_txt""2005-02-17"),
                                
=> array("tbl_txt""69.15"),
                                
=> array("tbl_txt_neg""57.20"),
                                
=> array("tbl_txt_neg""-17.28")),
                    
=> array(    => "00005",
                                
=> array("tbl_txt""Fuchs Petrolub Vz."),
                                
=> array("tbl_txt""DE0005790430"),
                                
=> array("tbl_txt""103"),
                                
=> array("tbl_txt""2005-04-29"),
                                
=> array("tbl_txt""65.12"),
                                
=> array("tbl_txt_pos""67.58"),
                                
=> array("tbl_txt_pos""3.78")),
                    
=> array(    => "00005",
                                
=> array("tbl_txt""Fuchs Petrolub Vz."),
                                
=> array("tbl_txt""DE0005790430"),
                                
=> array("tbl_txt""103"),
                                
=> array("tbl_txt""2005-02-17"),
                                
=> array("tbl_txt""75.00"),
                                
=> array("tbl_txt_neg""67.58"),
                                
=> array("tbl_txt_neg""-9.89")),
                    
=> array(    => "00019",
                                
=> array("tbl_txt""Postbank"),
                                
=> array("tbl_txt""DE0008001009"),
                                
=> array("tbl_txt""55"),
                                
=> array("tbl_txt""2005-04-29"),
                                
=> array("tbl_txt""36.30"),
                                
=> array("tbl_txt_neg""36.25"),
                                
=> array("tbl_txt_neg""-0.14")),
                    
=> array(    => "00020",
                                
=> array("tbl_txt""SOFTWARE AG O.N."),
                                
=> array("tbl_txt""DE0003304002"),
                                
=> array("tbl_txt""75"),
                                
=> array("tbl_txt""2005-04-29"),
                                
=> array("tbl_txt""26.83"),
                                
=> array("tbl_txt_neg""26.44"),
                                
=> array("tbl_txt_neg""-1.45")),
                    
10 => array(=> "00008",
                                
=> array("tbl_txt""Sartorius AG VZO O.N."),
                                
=> array("tbl_txt""DE0007165631"),
                                
=> array("tbl_txt""343"),
                                
=> array("tbl_txt""2005-02-18"),
                                
=> array("tbl_txt""16.71"),
                                
=> array("tbl_txt_pos""17.00"),
                                
=> array("tbl_txt_pos""1.74")),
                    
11 => array(=> "00001",
                                
=> array("tbl_txt""Arcelor S.A."),
                                
=> array("tbl_txt""LU0140205948"),
                                
=> array("tbl_txt""187"),
                                
=> array("tbl_txt""2005-04-14"),
                                
=> array("tbl_txt""17.10"),
                                
=> array("tbl_txt_neg""15.50"),
                                
=> array("tbl_txt_neg""9.36")));

$sort_string "<[1][1]>|<[4][1]>|<[7][1]>";
$test_array sort_array($test_array$sort_string);

echo 
"<pre>\n";
print_r($test_array);
echo 
"</pre>\n";
?>