Checks if a value exists in an array in PHP

Description

The following code shows how to checks if a value exists in an array.

Example


//from w  w  w  .java  2s  . co  m
<?php
    $people = array("XML", "CSS", "Java", "Javascript", 23);

    if (in_array("23", $people, TRUE)){
       echo "Match found<br>";
    }else{
       echo "Match not found<br>";
    }
    if (in_array("Glenn",$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>";
    }
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone