I've been scouring Google for an answer to this problem I'm having and have come up empty so far.
Basically, I'm creating an array of error messages, passing them as an array to a function, looping through the values, formatting and then returning them. For some reason the values do not get passed and I get an "Invalid argument supplied for foreach()" error.
//Create the error array
$error = 0;
$errorArray = array();
if(empty($_POST['amount']))
{
$error = 1;
array_push($errorArray,"Amount is required");
}
//Error Function
function makeErrors($err)
{
$output = 'ul';
foreach($err as $v)
{
$output .= '<li>'.$v.'</li>';
}
$output .= '</ul>';
return $output;
}
//Show the result
if($error == 1)
{
$theErrors = makeErrors($errorArray);
echo $theErrors;
}
If I just do a plain old print_r on $errorArray I get the expected value, so there's something lost when passing the array to the function. Any suggestions would be much appreciated.