I came up with a solution, but it's not very efficient
$pages = array('page_1.php', 'page_2-1.php', 'page_2-2-1.php', 'page_2-2.php', 'page_2.php');
$pos_array = array();
foreach ($pages as $page) {
$page_name = substr($page, 0, strpos($page, ".php"));
$parts = explode("_",$page_name);
$position_string = $parts[1];
array_push($pos_array,$position_string);
}
sort($pos_array);
$page_array = array();
foreach ($pos_array as $pos) {
foreach ($pages as $page) {
$page_name = substr($page, 0, strpos($page, ".php"));
$parts = explode("_",$page_name);
$position_string = $parts[1];
if($pos == $position_string){
array_push($page_array,$page);
}
}
}
$pages = $page_array;
Output:
[0] => page_1.php
[1] => page_2.php
[2] => page_2-1.php
[3] => page_2-2.php
[4] => page_2-2-1.php