Hi -
I am trying to apply a function to every member of an array.
I am using:
ARRAY
$colours = array(
"green",
"red",
"blue",
"orange",
"yellow");
CALL TO ARRAY_WALK
@array_walk($colours,myfunction($country,$origin,$weight,$price),$data);
FUNCTION
function myfunction ($value,$key,$data,$country,$origin,$weight,$price) {
$shipped = "<b>shipped</b>";
$notshipped = "<b>not shipped</b>";
if (strstr($data,$value)) {
$resulthtml = "$shipped";
}
else {
$resulthtml = "$notshipped";
}
echo ("$resulthtml");
}
######################
The array_walk function uses the array ($colours) and the function (myfunction) and parses $data which is some free text into the function (myfunction) as the third parameter, as it is placed at the end of the array walk syntax.
The problem that I have is that when I search $data for each of the strings which are members of the array $fruits, the $value doesn't seem to be returned and hence evaluated in the strstr part of the function.
Is this because the array_walk function only allows one additional parameter to be parsed into the user defined function ? or is there perhaps another more simple way of searching some free text for the string values of an array ?