PHP multidimensional array search by value

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

    You can use array_column for that.

    $user = array_search('5465', array_column($userdb, 'uid'));
    print_r($userdb[$user]);
    

    5465 is the user ID, uid is the key that contains user ID and $userdb is the array which is defined in the question.

提交回复
热议问题