PHP Classes

File: array_sort_example1.php

Recommend this page to a friend!
  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: 19 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(0 => array( 0 => "00016",
                               
1 => array("tbl_txt", "Allianz"),
                               
2 => array("tbl_txt", "DE0008404005"),
                               
3 => array("tbl_txt", "22"),
                               
4 => array("tbl_txt", "2005-04-29"),
                               
5 => array("tbl_txt", "91.40"),
                               
6 => array("tbl_txt_pos", "92.25"),
                               
7 => array("tbl_txt_pos", "0.93")),
                   
1 => array( 0 => "00001",
                               
1 => array("tbl_txt", "Arcelor S.A."),
                               
2 => array("tbl_txt", "LU0140205948"),
                               
3 => array("tbl_txt", "187"),
                               
4 => array("tbl_txt", "2005-04-14"),
                               
5 => array("tbl_txt", "17.10"),
                               
6 => array("tbl_txt_neg", "15.50"),
                               
7 => array("tbl_txt_neg", "-9.36")),
                   
2 => array( 0 => "00001",
                               
1 => array("tbl_txt", "Arcelor S.A."),
                               
2 => array("tbl_txt", "LU0140205948"),
                               
3 => array("tbl_txt", "406"),
                               
4 => array("tbl_txt", "2005-02-17"),
                               
5 => array("tbl_txt", "18.80"),
                               
6 => array("tbl_txt_neg", "15.50"),
                               
7 => array("tbl_txt_neg", "-17.55")),
                   
3 => array( 0 => "00017",
                               
1 => array("tbl_txt", "BASF"),
                               
2 => array("tbl_txt", "DE0005151005"),
                               
3 => array("tbl_txt", "40"),
                               
4 => array("tbl_txt", "2005-04-29"),
                               
5 => array("tbl_txt", "49.98"),
                               
6 => array("tbl_txt_pos", "50.05"),
                               
7 => array("tbl_txt_pos", "0.14")),
                   
4 => array( 0 => "00018",
                               
1 => array("tbl_txt", "EADS"),
                               
2 => array("tbl_txt", "NL0000235190"),
                               
3 => array("tbl_txt", "100"),
                               
4 => array("tbl_txt", "2005-04-29"),
                               
5 => array("tbl_txt", "22.02"),
                               
6 => array("tbl_txt_pos", "22.03"),
                               
7 => array("tbl_txt_pos", "0.05")),
                   
5 => array( 0 => "00007",
                               
1 => array("tbl_txt", "Elringklinger AG NA O.N."),
                               
2 => array("tbl_txt", "DE0007856023"),
                               
3 => array("tbl_txt", "100"),
                               
4 => array("tbl_txt", "2005-02-17"),
                               
5 => array("tbl_txt", "69.15"),
                               
6 => array("tbl_txt_neg", "57.20"),
                               
7 => array("tbl_txt_neg", "-17.28")),
                   
6 => array( 0 => "00005",
                               
1 => array("tbl_txt", "Fuchs Petrolub Vz."),
                               
2 => array("tbl_txt", "DE0005790430"),
                               
3 => array("tbl_txt", "103"),
                               
4 => array("tbl_txt", "2005-04-29"),
                               
5 => array("tbl_txt", "65.12"),
                               
6 => array("tbl_txt_pos", "67.58"),
                               
7 => array("tbl_txt_pos", "3.78")),
                   
7 => array( 0 => "00005",
                               
1 => array("tbl_txt", "Fuchs Petrolub Vz."),
                               
2 => array("tbl_txt", "DE0005790430"),
                               
3 => array("tbl_txt", "103"),
                               
4 => array("tbl_txt", "2005-02-17"),
                               
5 => array("tbl_txt", "75.00"),
                               
6 => array("tbl_txt_neg", "67.58"),
                               
7 => array("tbl_txt_neg", "-9.89")),
                   
8 => array( 0 => "00019",
                               
1 => array("tbl_txt", "Postbank"),
                               
2 => array("tbl_txt", "DE0008001009"),
                               
3 => array("tbl_txt", "55"),
                               
4 => array("tbl_txt", "2005-04-29"),
                               
5 => array("tbl_txt", "36.30"),
                               
6 => array("tbl_txt_neg", "36.25"),
                               
7 => array("tbl_txt_neg", "-0.14")),
                   
9 => array( 0 => "00020",
                               
1 => array("tbl_txt", "SOFTWARE AG O.N."),
                               
2 => array("tbl_txt", "DE0003304002"),
                               
3 => array("tbl_txt", "75"),
                               
4 => array("tbl_txt", "2005-04-29"),
                               
5 => array("tbl_txt", "26.83"),
                               
6 => array("tbl_txt_neg", "26.44"),
                               
7 => array("tbl_txt_neg", "-1.45")),
                   
10 => array(0 => "00008",
                               
1 => array("tbl_txt", "Sartorius AG VZO O.N."),
                               
2 => array("tbl_txt", "DE0007165631"),
                               
3 => array("tbl_txt", "343"),
                               
4 => array("tbl_txt", "2005-02-18"),
                               
5 => array("tbl_txt", "16.71"),
                               
6 => array("tbl_txt_pos", "17.00"),
                               
7 => array("tbl_txt_pos", "1.74")),
                   
11 => array(0 => "00001",
                               
1 => array("tbl_txt", "Arcelor S.A."),
                               
2 => array("tbl_txt", "LU0140205948"),
                               
3 => array("tbl_txt", "187"),
                               
4 => array("tbl_txt", "2005-04-14"),
                               
5 => array("tbl_txt", "17.10"),
                               
6 => array("tbl_txt_neg", "15.50"),
                               
7 => 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";
?>