Ok, here is where I stand, and I think I am over the initial roadblock.
1. I have the simplexml into an array. This is working.
$sortable = array();
foreach ($table as $case) {
$sortable[]=$case;
}
usort($sortable, function($a, b$) {
//I DID THIS TO TEST. The sort was not seeing the $a, $b as a string
//so I did the following
$test1 = (string)$a->DOCKETID; // This got me just the element we want to sort on
$test2 = (string)$b->DOCKETID; // This got me just the element we want to sort on
list($a1, $a2, $a3) = splitParts($test1); // Calling the function you provided below
list($b1, $b2, $b3) = splitParts($test2);
$x = strcmp($a1, $b1);
if ($x == 0) {
$y = $b2 - $a2;
if ($y == 0) {
return $b3 - $a3;
}
return $y;
}
return $x;
});
function splitParts($s) {
$k = strlen($s);
$a = ['','',''];
$i = 0;
$p = 0;
while ($i < $k) {
$c = $s[$i++];
if (ctype_digit($c) && $p==0) $p = 1;
if ($c=='-') {
$c = $s[$i++];
++$p;
}
$a[$p] .= $c;
}
return $a;
}
NOW - The last piece of my confusion. The results we want this time are as below. The original sort is what we wanted in my initial request, and that worked great. The piece I'm stuck on now is to sort differently, as below.
What we want:
CP2015-75
CP2015-76
CP2015-86
CP2015-93
CP2015-102
CP2015-106
CP2015-114
CP2016-3
CP2016-237
CP2016-238
CP2016-241
CP2016-242
CP2016-246
MC2016-164
MC2016-167
What we are getting:
CP2016-246
CP2016-242
CP2016-241
CP2016-238
CP2016-237
CP2016-3
CP2015-114
CP2015-106
CP2015-102
CP2015-93
CP2015-86
CP2015-76
CP2015-75
MC2016-167
MC2016-164