Help with multiarray sort for reverse natsort

I am extremely new to PHP, so bear with me. See details below:
I am trying to read data from an XML file that I do not control, which contains FileID’s. I need to present a dropdown box which sorts these as below:

What I have What I get with natsort($filelist_array); What I want (loaded into a dropdown box)
A2011-1 A2011-1 A2011-16
A2011-10 A2011-2 A2011-15
A2011-11 A2011-3 A2011-14
A2011-12 A2011-4 A2011-13
A2011-13 A2011-5 A2011-12
A2011-14 A2011-6 A2011-11
A2011-15 A2011-7 A2011-10
A2011-16 A2011-8 A2011-9
A2011-2 A2011-9 A2011-8
A2011-3 A2011-10 A2011-7
A2011-4 A2011-11 A2011-6
A2011-5 A2011-12 A2011-5
A2011-6 A2011-13 A2011-4
A2011-7 A2011-14 A2011-3
A2011-8 A2011-15 A2011-2
A2011-9 A2011-16 A2011-1
CP2015-102 CP2015-75 CP2015-114
CP2015-106 CP2015-76 CP2015-106
CP2015-114 CP2015-86 CP2015-102
CP2015-75 CP2015-93 CP2015-93
CP2015-76 CP2015-102 CP2015-86
CP2015-86 CP2015-106 CP2015-76
CP2015-93 CP2015-114 CP2015-75
CP2016-237 CP2016-3 CP2016-246
CP2016-238 CP2016-237 CP2016-242
CP2016-241 CP2016-238 CP2016-241
CP2016-242 CP2016-241 CP2016-238
CP2016-246 CP2016-242 CP2016-237
CP2016-3 CP2016-246 CP2016-3
MC2016-164 MC2016-164 MC2016-167
MC2016-167 MC2016-167 MC2016-164

I load the XML file into an array as such:
$FILEID = $xml->xpath(‘FileNOEventsDataSet/FileNOEventsData/FILEID’);

$FIRST_NAT_SORT = array();
foreach ($FILEID as $node){
$FIRST_NAT_SORT=(string)$node[0];
}

natsort($FIRST_NAT_SORT);

foreach ($FIRST_NAT_SORT as $NEWFILEID){
$html .=“<option value’”.$NEWFILEID.“’ >”.$NEWFILEID.“”;
}

This results in normal natsort result in the select box.

What I want is column 3 above, which sorts by everything to the left of the ‘dash’ alphabetically, and everything to the right of the dash descending.

I think I can do an explode on the $node[0], such as:
$SECOND_NAT_SORT = array();
$second_nat_sort = explode(“-”,$node[0]);
which results in $second_nat_sort[0] = ‘A2001’ and $second_nat_sort[1]=‘16’

I then try to do a multiarraysort, but I am lost at this point. Above my skill level.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.