Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»How to Check If a Value Exists in An Array in PHP

    How to Check If a Value Exists in An Array in PHP

    By RahulOctober 30, 20201 Min Read

    Q. How do I check if a specific value exists in an array in PHP. Write a sample PHP program to check if a value exists in an array.

    Advertisement

    Using PHP in_array() function

    Use PHP in_array() function to check whether a specific value exists in an array or not.

    Here is an sample PHP program, initialized an array with few element. Then check if an element is available in the defined array.

    Example

    1
    2
    3
    4
    5
    6
    7
    <?php
    $colors = array("Yellow", "Green", "Blue", "Pink", "Black");
     
    if(in_array("Green", $colors)){
        echo "Green element found in colors array";
    }
    ?>

    Output:

    Green element found in colors array
    

    array PHP
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9

    How to Install MySQL 8.0 on RHEL & CentOS Stream 9

    How to Split Large Archives in Linux using the Command Line

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9
    • How to Install MySQL 8.0 on RHEL & CentOS Stream 9
    • How to Split Large Archives in Linux using the Command Line
    • System.out.println() Method in Java: A Beginner’s Guide
    • Split Command in Linux With Examples (Split Large Files)
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.