3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = array( 'cover.xhtml', 'title.xhtml', 'copyright.xhtml', 'dedication.xhtml', 'toc_brief.xhtml', 'toc.xhtml', 'ch02_1.xhtml', 'ch02_2.xhtml', 'ch02_3.xhtml', 'ch02_4.xhtml', 'ch02_5.xhtml', 'ch02_6.xhtml', 'ch02_7.xhtml', 'ch02_8.xhtml', 'ch02_9.xhtml', 'ch02_10.xhtml' ); $array2 = array( '', 'title.xhtml', 'copyright.xhtml', 'dedication.xhtml', 'ch02_2.xhtml', 'ch02_2#454.xhtml', 'ch02_4.xhtml', 'ch02_1.xhtml', 'ch02_11.xhtml', 'ch02_12.xhtml', '' ); $customOrder = array_flip([ 'cover', 'title', 'copyright', 'dedication', 'toc_brief', 'toc', 'ch' ]); $uniqueFiltered = array_unique(array_filter(array_merge($array1, $array2))); array_multisort( array_map(fn($v) => $customOrder[strtok($v, '.012345789')], $uniqueFiltered), str_replace('#', '_', $uniqueFiltered), SORT_NATURAL, $uniqueFiltered ); var_export($uniqueFiltered);

preferences:
26.51 ms | 413 KiB | 5 Q