Skip to content
Advertisement

PHP Multidimenstional Associative Array Search by Value

I have an array where I want to search the name and get the key of the array that its associated to.

Examples

Assume we have the following 2-dimensional array with the second dimension being associated to a key:

JavaScript

The function call search_by_uid(“HenryB”) (name of the first user) should return 029102938093028 (The key of the array).

The function call search_by_uid(“Robert M”) should return 0283928293898303.

I have seen examples using multidemensional arrays where it returns the index but never the associated index. Please close if repeat question that i am unable to find.

Advertisement

Answer

JavaScript

Using a foreach loop to loop through all the values in the array until matching value is found, then the index is returned and the loop stops.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement