How to find the index of an element in an array using PHP ?
In this article, we will discuss how to find the index of an element in an array in PHP. Array indexing starts from 0 to n-1. We can get the array index by using the array_search() function. This function is used to search for the given element. It will accept two parameters.
- The first one is the element present in the array.
- The second is the array name.
Return Value: It returns the index number which is an Integer.
Note: We will get the index from indexed arrays and associative arrays.
Example 1: PHP program to get the index of the certain elements from the indexed array.
0 1 4
Example 2: The following example returns the index of an associative array.
0 1 4