if you are using php 5.3 and above, you can use closure to simplify your code:
$NUM = 5;
$items = array(1, 4, 5, 8, 0, 6);
$filteredItems = array_filter($items, function($elem) use($NUM){
return $elem < $NUM;
});
More Related Contents:
- How to make array inside in foreach loop – php? [closed]
- How can I sort arrays and data in PHP?
- Convert a PHP object to an associative array
- Sort array of objects by object fields
- Get the first element of an array
- PHP Array to JSON Array using json_encode(); [duplicate]
- How can I check if an array contains a specific value in php?
- How to reindex an array?
- How to sort a multidimensional array by a certain key?
- How to sort an array of UTF-8 strings?
- PDO fetch one column from table into 1-dimensional array
- Get all mysql selected rows into an array
- What is better in a foreach loop… using the & symbol or reassigning based on key?
- Select from mysql table WHERE field=’$array’?
- How to set an Arrays internal pointer to a specific position? PHP/XML
- Algorithm to get all possible string combinations from array up to certain length
- How to cast array elements to strings in PHP?
- Make multiple files to force-download
- Sort multidimensional array by date column, then use other column values if dates are the same
- Get date range between two dates excluding weekends
- How to merge two arrays by summing the merged values [duplicate]
- PHP merge arrays by value
- Find number which is greater than or equal to N in an array
- php split array into smaller even arrays
- PHP array replace after matching value [duplicate]
- MySQL query using an array [duplicate]
- PHP get previous array element knowing current array key
- how to change the array key to start from 1 instead of 0 [duplicate]
- Create PHP array from MySQL column
- Recreate original PHP array from print_r output [duplicate]