In php programming, the in_array () function searches for the given value in the array. In_array () defines and uses the in_array () function to search for a given value in the array. The description value of the in_array (value, array, type) parameter is required. Specifies the value to be searched in the array. Array is required. Specifies the array to be searched. Type is optional. If this parameter is set to true, check whether the data to be searched is of the same type as the value of the array. Returns true if the given value exists in the array. If the third parameter is set to true, the function returns true only when the element exists in the array and the data type is the same as the given value. If no parameter is found in the array, the function returns false. Note: If the value parameter is a string and the type parameter is set to true, the search area is case sensitive. Example 1: in_array instance.
$ People = array ("Peter", "Joe", "Glenn", "Cleveland ");
If (in_array ("Glenn", $ people ))
- {
- Echo "Match found ";
- }
- Else
- {
- Echo "Match not found ";
- }
- ?>
Output: Match found Example 2: in_array instance.
$ People = array ("Peter", "Joe", "Glenn", "Cleveland", 23 );
If (in_array ("23", $ people, TRUE ))
- {
- Echo "Match found
";
- }
- Else
- {
- Echo "Match not found
";
- } If (in_array ("Glenn", $ people, TRUE ))
- {
- Echo "Match found
";
- }
- Else
- {
- Echo "Match not found
";
- } If (in_array (23, $ people, TRUE ))
- {
- Echo "Match found
";
- }
- Else
- {
- Echo "Match not found
";
- }
- ?>
Output: Match not found Match found |