Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
validate elements of array
  • 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.
  • HarroHarro
    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.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion