PHP Classes

File: array_sort_example2.php

Recommend this page to a friend!
  Classes of Matthias Rothe   Advanced Array Sort   array_sort_example2.php   Download  
File: array_sort_example2.php
Role: Example script
Content type: text/plain
Description: Example of the Class in Use (Outputs Error Msgs)
Class: Advanced Array Sort
Sorts multidimensional arrays by multiple columns
Author: By
Last change: adjusted for better output reading in html browsers
Date: 18 years ago
Size: 6,839 bytes
 

Contents

Class file image Download
<?
$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")));

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

require(
"array_sort.class.inc");
$array_sort = new array_sort($test_array, "<[1][1]>|<[4][1]>|<[7][1]>");
if(!
$array_sort->error["flag"]){
  echo
"\n<b>Sortierter Array:</b>\n<br>\n";
  echo
"<p>\n<pre>\n";
 
print_r($array_sort->get_sorted_array());
  echo
"\n</pre>\n</p>";
  }
else echo
$array_sort->error["msg"];
?>