Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Problem 5. Custom Sorting
- //Write function that sort array according to the element with that index in the string. For example if given index is 2, sort array by //second index of string.
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <form method="post" action="CustomString.php">
- <input type="text" name="str1">
- <input type="submit" value="GO">
- </form>
- </body>
- </html>
- <?php
- $int=1;//sorting index
- $myArr=array("ovca","kashta","agne","abreviatura","buldog", "123456789");
- foreach($myArr as $v){
- $newArr[$v]=substr($v, $int);
- }
- asort($newArr);
- foreach($newArr as $k=>$vv){
- $finalArr[]=$k;
- }
- echo '<pre>' . print_r($finalArr, true) . '</pre>';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement