Php multidimensional array search by value

I have an array where I want to search the userid and get the key of the array.
Deepak Sharma
Asked 13-12-2024
186

Answer (1)
For example $users = array( array( 'userid' => '100', 'name' => 'Sandra Shush', ), array( 'userid' => '5465', 'name' => 'Stefanie Mcmohn', ), array( 'userid' => '40489', 'name' => 'Michael', ) ); $key = array_search(40489, array_column($users, 'uid')); echo $users[$key]['name']; Output: Sandra Shush.
Deepak Sharma
Asked 28-10-2018
45 Likes
Comments
Write comment

Submit your answer