array_filter
:
The official documentation for PHP is full of very understandable examples for each function. These examples are given by the documentation or the community, and follows each function description.
PHP Documentation
Form validation :
A little code example for the script called by your POST form. Of course a lot of changes to this can be made to display the errors the way you like, and perhaps tune more precise checks on each data.
<?php
if (isset($_POST['name']) && !ctype_upper($_POST['name'])) {
$errors[] = 'name should be uppercase';
}
if (isset($_POST['email']) && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errors[] = 'email is invalid';
}
if (isset($_POST['password']) && strlen($_POST['password']) >= 6 && strlen($_POST['password']) <= 16)) {
$errors[] = 'password should be between 6 and 16 characters length';
}
if (isset($errors)) {
// do not validate form
echo '<ul><li>' . join('</li><li>', $errors) . '</li></ul>';
// ... include the html code of your form here
}
else {
// ... call things that must work on validated forms only here
}
solved Php Filter array