Current Location: Home> Function Categories> in_array

in_array

Check if there is a value in the array
Name:in_array
Category:Array
Programming Language:php
One-line Description:Checks whether the specified value exists in the array.

Definition and usage

in_array() function searches for the specified value in the array.

Note: If the search parameter is a string and the type parameter is set to TRUE, the search is case sensitive.

Example

Example 1

Search the value "Glenn" in the array and output some text:

 <?php
$people = array ( "Bill" , "Steve" , "Mark" , "David" ) ;

if ( in_array ( "Mark" , $people ) )
  {
  echo "Match Found" ;
  }
else
  {
  echo "Match not found" ;
  }
?>

Try it yourself

Example 2

Use all parameters:

 <?php
$people = array ( "Bill" , "Steve" , "Mark" , "David" ) ;

if ( in_array ( "23" , $people , TRUE ) )
  {
  echo "Match Found<br>" ;
  }
else
  {
  echo "Match not found<br>" ;
  }
if ( in_array ( "Mark" , $people , TRUE ) )
  {
  echo "Match Found<br>" ;
  }
else
  {
  echo "Match not found<br>" ;
  }

if ( in_array ( 23 , $people , TRUE ) )
  {
  echo "Match Found<br>" ;
  }
else
  {
  echo "Match not found<br>" ;
  }
?>

Try it yourself

grammar

 in_array ( search , array , type )
parameter describe
Search Required. Specifies the value to be searched in the array.
array Required. Specifies the array to search.
type Optional. If this parameter is set to true, check whether the searched data is the same as the value of the array.

illustrate

Return true if the given value search exists in the array array . If the third parameter is set to true, the function returns true only if the element exists in the array and the data type is the same as the given value.

If no argument is found in the array, the function returns false.

Note: If the search parameter is a string and the type parameter is set to true, the search is case sensitive.

Similar Functions
Popular Articles