Simple curiosity, is there any way to convert what this following into a switch loop?
PHP :
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error = array('type' => 'error', 'value' => 'email');
}
elseif (!preg_match($regex_name, $username)) {
$error = array('type' => 'error', 'value' => 'username');
}
elseif (!preg_match($regex_name, $firstname) && preg_match($regex_name, $lastname)) {
$error = array('type' => 'error', 'value' => 'name');
}
elseif ($password !== $password_conf) {
$error = array('type' => 'error', 'value' => 'password');
}
elseif (checkdate($birthday_d, $birthday_m, $birthday_y) == false) {
$error = array('type' => 'error', 'value' => 'date');
}
else {
$error = array('type' => 'success');
}
Thanks.
Just for completeness an example of what a transformation to a switch would look like:
switch(true) {
case (!filter_var($email, FILTER_VALIDATE_EMAIL)):
$error = array('type' => 'error', 'value' => 'email');
break;
case (!preg_match($regex_name, $username)):
$error = array('type' => 'error', 'value' => 'username');
break;
//...
}
In the end this is just a complicated way to say if this is true
.