LMSouq
php-dev Open

Get the first level key of the first row containing a specified column value in a 2d array

RA
Rachit
1 month ago
3 views
Problem Description
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: $userdb = array( array( 'uid' => '100', 'name' => 'Sandra Shush', 'pic_square' => 'urlof100' ), array( 'uid' => '5465', 'name' => 'Stefanie Mcmohn', 'pic_square' => 'urlof100' ), array( 'uid' => '40489', 'name' => 'Michael', 'pic_square' => 'urlof40489' ) ); The function call `search_by_uid(100)` (uid of first user) should return `0`. The function call `search_by_uid(40489)` should return `2`. I tried making loops, but I want a faster executing code.

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base