fork(4) download
  1. <?php
  2.  
  3. $_data = [
  4. 'Mr. Bala',
  5. 'Mrs. Camel',
  6. 'Mr. Santhosh',
  7. 'Mr. Vinoth',
  8. 'Avinosh',
  9. 'Camel'
  10. ];
  11.  
  12.  
  13. usort($_data, 'sortByName');
  14. print_r($_data);
  15.  
  16. function sortByName($a, $b) {
  17. $remove = [' ', '.', 'Mrs', 'Miss', 'Ms', 'Master', 'Dr', 'Mr'];
  18.  
  19. $a = str_replace($remove, '', $a);
  20. $b = str_replace($remove, '', $b);
  21.  
  22. return strcasecmp($a, $b);
  23. }
  24.  
  25.  
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Avinosh
    [1] => Mr. Bala
    [2] => Camel
    [3] => Mrs. Camel
    [4] => Mr. Santhosh
    [5] => Mr. Vinoth
)