PHP multidimensional array search by value

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

    $search1 = 'demo';
    $search2 = 'bob';
    $arr = array('0' => 'hello','1' => 'test','2' => 'john','3' => array('0' => 'martin', '1' => 'bob'),'4' => 'demo');
    foreach ($arr as $value) { 
        if (is_array($value)) { 
            if (in_array($search2, $value)) { 
                echo "successsfully";    
                //execute your code 
            }
        } else {  
            if ($value == $search1) { 
                echo "success";
            }
        }
     }
    

提交回复
热议问题