SproutCMS

This is the code documentation for the SproutCMS project

function arrayCheck()

Run a validation check against each value in an array.
Behaviour is very similar to the Validator::check method.

Only supports single-depth arrays

Errors are put into the field_errors array under a subkey matching the array key

Return value is an array of key => boolean with the validation result for each key

Usage

array $Validator->arrayCheck ( string $field_name , callable $func );

Example

$data = ['vals' => [1, 2, 'A', 'B', 5]];
$validator = new Validator($data);
$result = $validator->arrayCheck('vals', 'Validity::positiveInt');
// $result now contains [true, true, false, false, true]
$errs = $validator->getFieldErrors();
// $errs now contains [ 'vals' => [2 => [...], 3 => [...]] ]

Arguments

  1. string $field_name
    The field to check
  2. callable $func
    The function or method to call.

Return value

  • array
    Key => Boolean True if validation was successful, false if it failed