Created
April 2, 2014 11:10
-
-
Save bondarewicz/9932113 to your computer and use it in GitHub Desktop.
PHP: return any specific (2nd or 3rd largest) number from array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function whats_largest($arr, $idx) | |
| { | |
| sort($arr, SORT_NUMERIC); | |
| return($arr[count($arr) - intval($idx)]); | |
| } | |
| $array = array(); | |
| for ($i = 1; $i <= 10; $i++) { | |
| array_push($array, rand ( 1, 1000 )); | |
| } | |
| print_r($array); | |
| echo whats_largest($array,2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment