You can use usort to sort the object $children
.
The function to sort after you got the $children
object can be like this:
usort( $children, function($a, $b) {
$ai = filter_var($a->name, FILTER_SANITIZE_NUMBER_INT);
$bi = filter_var($b->name, FILTER_SANITIZE_NUMBER_INT);
if ($ai == $bi) {
return 0;
}
return ($ai < $bi) ? -1 : 1;
});