Problem with array_filter ion combination with array_search

Hi all,

I’ve got an problem with a function i’ve written, the first example works fine, it calls the function array_search to look for a predefined value in a multidimensional array. when found it returns true.

[code]<? php
function search_type($string) {
global $grammar;
return array_search($string,$grammar[banned]);
}

function check_4_banned($string){
$result = array_filter($string, search_type);
$keys = array_keys($result);
$i=0;
$ii = count($keys);
if($i != $ii){
return true;
}else{
return false;
}
}
?>
[/code]

Now the problem is the array is multidimensional, so if i predefine the array it works. What i wanted to do is give the function an 2nd argument so that the array is a varriable like this:

[code]

<? php function search_type($string, $type) { global $grammar; return array_search($string,$grammar[$type]); } function check_4_banned($string, $type){ $result = array_filter($string, search_type(, $type)); $keys = array_keys($result); $i=0; $ii = count($keys); if($i != $ii){ return true; }else{ return false; } } ?> [/code]

ofcourse it returns an error, unexpected ‘,’
I placed the comma there because it’s the 2nd var
when i remove the comma it returns Missing argument 2 for search_type(). does anybody know how i can resolve this problem,

I know i could use the In_array() function to check if a variable exists in an array but there is more to this function then just return true or false, it needs to return the banned words in a new array called: $banned

I would be very greatfull :)

Kind regards,

Bram Koster

You cannot leave mandatory parameters blank when calling functions:

[php]
function check_4_banned($string, $type){
$result = array_filter($string, search_type("", $type));
[ … ]
}
[/php]

The above example would work, but requires an extra check in the search_type() function. I think that’s as close as you can get to what you want.

Sponsor our Newsletter | Privacy Policy | Terms of Service