Multidimensional array search by value in PHP

In this short article, we’ll talk about multidimensional array search by value in PHP. Here, you will see how to find the value from a multidimensional array and return the key using PHP.

Using the array_search() function, we will easily do this task. There are two parameters required in this function and the last one is optional. The first one is a value that we want to find in the array and the second one is an array. Let’s take an example for demonstration.

Example

In this example, we will have two arrays $employees and $employeesData. We will find the email of the employees from the $employeesData array and create a new array.

Using the following syntax, we can find the key using the array_search() function.

Let’s use the following code to get the output.

Output:

Run the above code and check the output.

Reference article: Remove keys from an associative array in PHP

That’s it for today.
Thank you for reading. Happy Coding..!!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *