I made the function which will return me an array with all unprovided informations from user, but I can't get it to work with first element in array.
This is the data which is used as parameter in function:
$data = array(
$_POST["firstName"] => "first name",
$_POST["lastName"] => "last name"
);
print_r(return_not_provided($data));
This is the function:
function return_not_provided($formFields) {
$notProvidedFields = array();
foreach ($formFields as $field => $value) {
if (!isset($field) || empty($field))
array_push($notProvidedFields, $value);
}
return $notProvidedFields;
}
And it returns this:
Array ( [0] => last name )
Script notifies me that both indexes are undefined (firstName
and lastName
) but doesn't push them both in array.