I'm recoding a script of mine to not use databases (MySQL) in an effort to get more coding experience and to lower the number of external dependencies.
Right now I'm trying to build a associative array ordering loop but have hit a snag.
I found the following on PHP.net: http://us3.php.net/array_multisort - Example 3; but that example deals with a known set of array key names. I want to create a loop that would allow me to deal with any associative array. The arrays are always 2-dimensioned and will have column names for key values like this:
Datastruct 1:
$aData[0]['foo'] = ...
$aData[0]['bar'] = ...
$aData[0]['this'] = ...
$aData[0]['that'] = ...
Datastruct 2:
$aData[0]['ID'] = ...
$aData[0]['first'] = ...
$aData[0]['middle'] = ...
$aData[0]['last'] = ...
$aData[0]['age'] = ...
Datastruct 3:
$aData[0]['part #'] = ...
$aData[0]['description'] = ...
As you can see, the number of columns and column names will never be the same all the time.
How do you set up a foreach loop that would allow one to define sorts on any combination of columns when an ordering value(s) is defined like:
- foo
- foo,this
- bar,that
- last,first,middle
TIA