Home Tutorial Php Phparray php array contains value

 
 

Share on Google+Share on Google+
php array contains value
Posted on: October 28, 2009 at 12:00 AM
Advertisement
This PHP Tutorial section we will demonstrates the use of in_array() function in the php arrays

  • PHP in_array() function is used to check whether the given value is presesnt in the array or not.


PHP Array Contains Value Example

in_array() function is used to check whether the given value is presesnt in the  array or not.

Example

<?php

    $ar1=array("jack","mac","rob","tom","jennifer");

    $val="mac";

    $val1="mic";

    foreach ($ar1 as $a)

    echo " ".$a;

    echo "<br>";

    if(in_array($val,$ar1)) {

    echo "$val is present in the array";

       }

    else {

    echo "$val is not present in the array";

       }

    echo "<br>";

    if(in_array($val1,$ar1)) {

    echo "$val1 is present in the array";

       }

    else {

    echo "$val1 is not present in the array";

       }

?>

    Output

    jack mac rob tom jennifer
    mac is present in the array
    mic is not present in the array

Advertisement

Related Tags for php array contains value:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 28, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com