PHP In_array() Array Function Example

The PHP in_array() function is a bulit in function. in_array() function checks if a value exists or not in a array. It returns TRUE if the given items is found in the given array, and FALSE otherwise.

PHP in_array() Syntax

The PHP in_array() function syntax is in_array(search, array, type)


search : Required. Specifies what to search for

array : Required. it specifies the array in which we want to search.

type : Optional. If this parameter is set to TRUE, the in_array() function searches for the search-string and specific type in the array.

Example : 

  $items = array("Mobile", "TV", "Camera", "iPhone");

  return (in_array("iPhone", $items))
         ? "Yes" : "Not";


in_array() output




Hope it can help you.


#php #array