require_once('classes/class.validation.php');
$array = $_POST['array'];
$pass_profanity = false;
$validation = new Validation;
function check_for_profanity($input){
if(is_array($input)){
foreach($input as $row){
if(is_array($row)){
check_for_profanity($input);
} else {
$pass_profanity = $validation->check_for_profanity($row);
}
}
} else {
$pass_profanity = $validation->check_for_profanity($input);
return;
}
return;
}
check_for_profanity($array);
But I get the error:
Notice: Undefined variable: validation in
/Library/WebServer/Documents/file.php on line 22Fatal error: Call to a member function check_for_profanity() on a
non-object in /Library/WebServer/Documents/file.php
on line 2
I can’t figure it out, any thoughts???
Thanks in advance!
You can either gain access to the variable in your function with
global:Or, the better way would be to retrieve it via a parameter:
Read the PHP manual – variable scope for more information