PHP multidimensional array search by value

前端 未结 23 3362
情歌与酒
情歌与酒 2020-11-21 04:45

I have an array where I want to search the uid and get the key of the array.

Examples

Assume we have the following 2-dimensional array:

<
23条回答
  •  青春惊慌失措
    2020-11-21 05:38

    Try this also

    function search_in_array($srchvalue, $array)
    {
        if (is_array($array) && count($array) > 0)
        {
            $foundkey = array_search($srchvalue, $array);
            if ($foundkey === FALSE)
            {
                foreach ($array as $key => $value)
                {
                    if (is_array($value) && count($value) > 0)
                    {
                        $foundkey = search_in_array($srchvalue, $value);
                        if ($foundkey != FALSE)
                            return $foundkey;
                    }
                }
            }
            else
                return $foundkey;
        }
    }
    

提交回复
热议问题