vishnu
vishnu

Reputation: 495

Multidimensional array search using php

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

Answers (2)

Zakaria
Zakaria

Reputation: 15070

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

Upvotes: 0

powtac
powtac

Reputation: 41040

function ($haystack, $tag) {
    foreach ($haystack as $key => $value) {
        if (in_array($tag, explode(',', $value['meta_tags']) {
            return true;
        }
    }
}

Upvotes: 1

Related Questions