fork download
  1. <?php
  2.  
  3. $array = [
  4. '215/75R17.5',
  5. '235/75R17.5',
  6. '7.01/75R17',
  7. '8.25R16',
  8. '7.00R16',
  9. '11R22.5',
  10. '7.50R16',
  11. ];
  12.  
  13. function customCompare($x, $y) {
  14. $x = explode('R', $x);
  15. $y = explode('R', $y);
  16. if ($x[1] != $y[1]) return $x[1] < $y[1] ? -1 : 1;
  17. return strnatcmp($x[0], $y[0]);
  18. }
  19.  
  20. usort($array, 'customCompare');
  21. print_r($array);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 7.00R16
    [1] => 7.50R16
    [2] => 8.25R16
    [3] => 7.01/75R17
    [4] => 215/75R17.5
    [5] => 235/75R17.5
    [6] => 11R22.5
)