<?php
function closest($array, $number) {
sort($array);
foreach ($array as $a) {
if ($a >= $number) return $a;
}
return end($array); // or return NULL;
}
?>
More Related Contents:
- How to sort a date array in PHP
- Add elements to array which has gapped numeric keys to form an indexed array / list
- Compare two array and get all differences
- PHP create new array by value
- Get first and second element of array [duplicate]
- PHP Multidimensional associative array to HTML table
- count how many duplicate keys are in array of objects?
- How to access and manipulate multi-dimensional array by key names / path?
- Is there a function to extract a ‘column’ from an array in PHP?
- How to add elements to an empty array in PHP?
- PHP Sort Array By SubArray Value
- Using a string path to set nested array data [duplicate]
- I have an array of integers, how do I use each one in a mysql query (in php)? [duplicate]
- How to get random value out of an array?
- Finding the subsets of an array in PHP
- How to combine two arrays together?
- How can I echo or print an array in PHP?
- Get min and max value in PHP Array
- Flatten multidimensional array concatenating keys [duplicate]
- Array to Object and Object to Array in PHP – interesting behaviour
- How to get the last n items in a PHP array as another array?
- Difference between array_push() and $array[] =
- Group 2d array data by one column and sum other columns in each group (separately)
- Efficiency of using foreach loops to clear a PHP array’s values
- Find min/max in a two dimensional array
- how to sort a multidemensional array by an inner key
- CMS Routing in MVC
- Recursive array_search
- phpexcel Allowed memory size of 134217728 bytes exhausted [duplicate]
- Check if all values in array are the same