Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
validate elements of array
JeanAlesi
September 2015
I'm doing an ajax call, and passing an array with user ids to the server.
Can anyone recommend to me a good solution to validating the elements of the array. They must all be numeric.
Harro
September 2015
Accepted Answer
Use array_reduce() with a closure:
$checknumeric = function($carry, $value) {
return $carry and is_numeric($value);
};
$result = (is_array($input) and array_reduce($input,$checknumeric,true));
$result will be true if $input is an array and all array values pass the is_numeric() test.
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,089
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
261
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
September 2015