I have a question concerning the right way to pass an array to a function
After validating a form, I get an array of errors corresponding to each form field. i.e.
$errors = array(
"First_Name" => "Missing first name",
"Email" => "Invalid email address",
...
)
In order to display this errors I created a function
function print_error_message($field, $errors) {
if($errors[$field])
echo '<span class="error-msg">' . $errors[$field] . '</span>';
}
And I call this function after every html field to check whether this field has an error:
<input name="First_Name" value="<?php echo $First_Name ?>" />
<?php print_error_message("First_Name", $errors) ?>
...
So, since I have a lot of form fields, and a lot of errors, is it a good practice to pass '$errors' array every time I call the function. Or should I use global
or passing by reference?