I am looping through an associative array and trying to match the whole word from the needle array into the haystack array. The following code works perfectly but returns too many results since it's matching any occurance of the string:
$result = array();
$name1 = array();
$name2 = array();
foreach($object->organizations as $o) {
foreach($objectCrunch as $o2) {
$name1 = $o->name;
$name2 = $o2->name;
if(stristr($name2, $name1)) {
$result[] = $o2->permalink;
}
}
}
When I try the following code:
$result = array();
$name1 = array();
$name2 = array();
foreach($object->organizations as $o) {
foreach($objectCrunch as $o2) {
$name1 = $o->name;
$name2 = $o2->name;
$pattern = "'/\b" . $name2 . "\b/i'";
if(preg_match($pattern, $name1)) {
$result[] = $o2->permalink;
}
}
}
I get an empty array. Any help getting the last piece of code working would be great.
Thanks, Greg