Reputation: 495
I have multidimensional array like this:
Array
(
[0] => Array
(
[id] => 10184
[meta_tags] => tag1,tag2
)
)
How do i search by keyword (example, tag1
) in an array.
Thank u.
Upvotes: 0
Views: 818
Reputation: 15070
I think you have to use a recursive function since arrays don't have the same dimensions.
Upvotes: 0
Reputation: 41040
function ($haystack, $tag) {
foreach ($haystack as $key => $value) {
if (in_array($tag, explode(',', $value['meta_tags']) {
return true;
}
}
}
Upvotes: 1