I'm rewritting a script and want to stay way from having to need a database (ala MySQL) for it. I'm building a AoA and wanted to know if it was possible to sort this type of struct (versus passing the data to MySQL and doing a SQL statement)?

Row[0] contains the col names:

$aData[0][0] = column 1 name ("foo")
$aData[0][1] = column 2 name ("bar")
...
$aData[1][0] = column 1 data ("test")
$aData[1][1] = column 1 data ("this")
...
$aData[2][0] = column 2 data ("for")
$aData[2][1] = column 2 data ("bugs")
...

Is there a pre-built way to specify a col name (or number) to sort on?

TIA

    Ok, I found the following on PHP.net:

    http://us3.php.net/array_multisort - Example 3:

    	// Obtain a list of columns
    	foreach ($data as $key => $row) {
       		$volume[$key]  = $row['volume'];
       		$edition[$key] = $row['edition'];
    	}
    
    // Sort the data with volume descending, edition ascending
    // Add $data as the last parameter, to sort by the common key
    array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);

    I understand it but the problem I'm having with it is the variable names: $volume and $edition.

    How do I code that part to deal with any associative array?

      Write a Reply...