PHP multidimensional array search by value

前端 未结 23 3332
情歌与酒
情歌与酒 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:33

    I had to use un function which finds every elements in an array. So I modified the function done by Jakub Truneček as follow:

    function search_in_array_r($needle, $array) {
        $found = array();
        foreach ($array as $key => $val) {
            if ($val[1] == $needle) {
                array_push($found, $val[1]);
            }
        }
        if (count($found) != 0)
            return $found;
        else
            return null;
    }
    

提交回复
热议问题