Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ####################
- ### Assignment 1 ###
- ####################
- /**
- * Sort $words array with respect to characters length in ascending order.
- * @type {Array}
- */
- $words = [
- 'zoologicobotanical',
- 'triplocaulescent',
- 'ropewalk',
- 'funiculitis',
- 'pandect',
- 'shrivel',
- 'procuratorate',
- 'locular',
- 'unrevealingly',
- 'strepor',
- 'clinty',
- 'Sicani',
- 'fringent',
- 'percipiency',
- ];
- function sortWords($left,$right){
- $diff= strlen($left) - strlen($right);
- if(!$diff){
- return strcmp($left,$right);
- }
- return $diff;
- }
- usort($words, 'sortWords');
- var_dump($words);
- ####################
- ### Assignment 2 ###
- ####################
- /**
- * Sort $name array in alphabetical order a-z.
- * @type {Array}
- */
- $names = [
- 'Teresia',
- 'Shane',
- 'Denis',
- 'Yuriko',
- 'Ying',
- 'Erick',
- 'Leda',
- 'Davis',
- 'Milissa',
- 'Hollis',
- 'Felicia',
- 'Anh'
- ];
- $sortName = sort($names);
- var_dump($names ,'sortName');
Add Comment
Please, Sign In to add comment