Page 1 of 1

problem to do the trick

Posted: Sat Dec 22, 2012 7:19 am
by sendy
example i have a form validation script which test if user has filled all of the fields.
i set up the $errors variable, and test each field if they have errors or not

Code: Select all

$required_fields = array('username' , 'password', 'email');
foreach($required_fields as $field)
        $errors[] = "Please fill {$_POST[$field]}";
then i want to:
Add code to the handling of the $errors variable on the page that uses a foreach loop if $errors is an array, or just prints the value of $errors otherwise.

what im thinking is using is_array() function, to test $errors :

Code: Select all

if( is_array($errors) )

then i tried to use var_dump() to test $errors (even if there is only 1 error) unfortunately its still an array.

i cant figure it out..