3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ "A - 1.0 - Title Page.PDF", "A - 2.2 - Enlarged Floor Plans", "A - 2.1.0 - Structural Details.PDF", "E - 1.0 - Electrical Title Page.PDF", "A - 1.2 - Floor Plan.PDF", "P - 1.0 - Plumbing Title Page2.PDF", "A - 2.1.1 - Structural Details.PDF", "C - 1.0 - Civil Title Page.PDF", "M - 1.0 - Mechanical Title Page.PDF", "ESC - 1.0 - Erosion Control Plan.PDF", "P - 1.0 - Plumbing Title Page.PDF", ]; $priorities = array_flip(['A', 'ESC', 'C', 'M', 'E', 'P']); usort($arr, function ($a, $b) use ($priorities) { [$categoryA, $versionA, $nameA] = explode(' - ', $a, 3); [$categoryB, $versionB, $nameB] = explode(' - ', $b, 3); return $priorities[$categoryA] <=> $priorities[$categoryB] // priorities as first criteria ?: version_compare($versionB, $versionA) // then descending versions as second criteria ?: $nameA <=> $nameB; // then compare names ascending }); var_export($arr);
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
array ( 0 => 'A - 2.2 - Enlarged Floor Plans', 1 => 'A - 2.1.1 - Structural Details.PDF', 2 => 'A - 2.1.0 - Structural Details.PDF', 3 => 'A - 1.2 - Floor Plan.PDF', 4 => 'A - 1.0 - Title Page.PDF', 5 => 'ESC - 1.0 - Erosion Control Plan.PDF', 6 => 'C - 1.0 - Civil Title Page.PDF', 7 => 'M - 1.0 - Mechanical Title Page.PDF', 8 => 'E - 1.0 - Electrical Title Page.PDF', 9 => 'P - 1.0 - Plumbing Title Page.PDF', 10 => 'P - 1.0 - Plumbing Title Page2.PDF', )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
134.54 ms | 408 KiB | 5 Q