Is there a function to do this?
For example if I have an array like 1,1,3,2,1,2,3,2,2,3,3,2,5,1 The function should return true if and only if all the numbers in the array are less than 5
Is there a function to do this?
For example if I have an array like 1,1,3,2,1,2,3,2,2,3,3,2,5,1 The function should return true if and only if all the numbers in the array are less than 5
Why you don't create your own function?
You could use
array_filter
to run a command over each argument, and ensure that the list is empty, like so:@Mchl already gave you the most concise and elegant solution, but I spent some minutes to create an ugly one-liner solution and will post my quirky and hackish solution as a curiosity or a warning example.
For more info on PHP closures, consult the Anonymous functions in the PHP manual.
array_map
that everyone is suggesting is of not much use here.array_reduce
would be:But @Mchl's use of
max
is of course best.