We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon Array Validation

[relatedchildid] => Array ( [0] => asdf [1] => 12 [2] => 22 ).

I have the above given array and I want to validate each of the array element to validate and accept only numbers only 0 to 9.Can any one please share the example code.



85.5k

$arr = ['asd',12,3,5,6];

        if (is_array($arr)){
            throw new \Phalcon\Exception('Whatver');
        }

        $newArr = [];
        foreach ($arr AS $value){
            $value = intval($value);

            if ($value >= 0 && $value <= 9){
                $newArr[] = $value;
            }
        }

        if (count($newArr) == 0 ){
            //this flash message or whatever
        }

Phalcon does not provide any built in validation function for this ??