Returning foreach value from funtion to array
I have a function and I am passing array argument in it to validate it.
Then on the next page I am inserting the array arguement. As below..
function check_subject($sub_array)
{
foreach($sub_array as $value)
{
if (!empty($value))
{
if (!preg_match('/^[0-9a-zA-Z ]{2,20}$/', $value))
{
return "Not supported format";
}
}
}
}
Other page I am inserting as $errors[] = check_subject($g8_sub_vali); and
I am storing the return result in an $error[] array.
Than I am printing error if any else do somehitng as below..
if($errors)
{
foreach ($errors as $msg)
{
if(!empty($msg))
{
echo " - $msg<br />\n";
}
}
}
else
{
echo "There is no error";
}
But I am not getting the else loop value that is "There is no error". I
think there is a problem in returning from function. Can you please
suggest me.
No comments:
Post a Comment