if (!is_array($array) || count($array) == 0) {
return false;
}
-
+
// Do a sort by custom function with it included in the call
// This lets me directly use $name and $parent in the sort function
uasort($array, function ($a, $b) use ($name, $parent) {
-
// If there's a parent, append the name of this entry to the parent
// The '~~~' simply keeps appended strings from any chance of a match with something else
if ($a[$parent]['value']) {
$aVal = $a[$parent]['name'].'~~~'.$a['name'];
} else {
// Otheriwse just use the name.
- $aVal = $a['name'];
+ $aVal = $a['name'].'~~~';
}
// Same for b value
if ($b[$parent]['value']) {
$bVal = $b[$parent]['name'].'~~~'.$b['name'];
} else {
- $bVal = $b['name'];
+ $bVal = $b['name'].'~~~';
}
if ($aVal > $bVal) {