3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $array = array("100_1", "100_2", "100_3", "100_11", "101_1", "102_1", "102_2", "103_1", "103_2", "103_3", "104_1", "104_2"); natsort($array); foreach($array as $value) { $parts = explode('_', $value); $result[$parts[0]] = $value; } $result = array_values($result); print_r($result);
Output for 4.3.0 - 7.1.0
Array ( [0] => 100_11 [1] => 101_1 [2] => 102_2 [3] => 103_3 [4] => 104_2 )