Guest User

Untitled

a guest
Oct 18th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2. ####################
  3. ### Assignment 1 ###
  4. ####################
  5.  
  6. /**
  7. * Sort $words array with respect to characters length in ascending order.
  8. * @type {Array}
  9. */
  10.  
  11. $words = [
  12. 'zoologicobotanical',
  13. 'triplocaulescent',
  14. 'ropewalk',
  15. 'funiculitis',
  16. 'pandect',
  17. 'shrivel',
  18. 'procuratorate',
  19. 'locular',
  20. 'unrevealingly',
  21. 'strepor',
  22. 'clinty',
  23. 'Sicani',
  24. 'fringent',
  25. 'percipiency',
  26. ];
  27.  
  28. function sortWords($left,$right){
  29. $diff= strlen($left) - strlen($right);
  30. if(!$diff){
  31. return strcmp($left,$right);
  32. }
  33. return $diff;
  34. }
  35. usort($words, 'sortWords');
  36. var_dump($words);
  37. ####################
  38. ### Assignment 2 ###
  39. ####################
  40.  
  41. /**
  42. * Sort $name array in alphabetical order a-z.
  43. * @type {Array}
  44. */
  45.  
  46. $names = [
  47. 'Teresia',
  48. 'Shane',
  49. 'Denis',
  50. 'Yuriko',
  51. 'Ying',
  52. 'Erick',
  53. 'Leda',
  54. 'Davis',
  55. 'Milissa',
  56. 'Hollis',
  57. 'Felicia',
  58. 'Anh'
  59. ];
  60. $sortName = sort($names);
  61. var_dump($names ,'sortName');
Add Comment
Please, Sign In to add comment