0

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.

jensgram
  • 31,109
  • 6
  • 81
  • 98
vishnu
  • 495
  • 4
  • 12
  • 26
  • 1
    ... and then take a look at [this answer](http://stackoverflow.com/questions/1019076/how-to-search-by-key-value-in-a-multidimensional-array-in-php/1019534#1019534). – jensgram Mar 07 '11 at 12:49

2 Answers2

1
function ($haystack, $tag) {
    foreach ($haystack as $key => $value) {
        if (in_array($tag, explode(',', $value['meta_tags']) {
            return true;
        }
    }
}
powtac
  • 40,542
  • 28
  • 115
  • 170
0

I think you have to use a recursive function since arrays don't have the same dimensions.

Please, refer to that post that features a recursive function really useful.

Zakaria
  • 14,892
  • 22
  • 84
  • 125