Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    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

    RahulBy 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.

    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

    PHP
    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
    Previous ArticleHow to Install Postman on Ubuntu 18.04
    Next Article How to Install Python 3.9 on Amazon Linux 2

    Related Posts

    How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04

    Updated:May 9, 20223 Mins Read

    How to Find Django Install Location in Linux

    Updated:April 27, 20221 Min Read

    (Resolved) – ReactJS 404 Error on Page Reload

    2 Mins Read

    How To Install LAMP Stack on Ubuntu 22.04 LTS

    Updated:April 20, 20225 Mins Read

    5 Methods to Print an Array in Java

    Updated:April 21, 20222 Mins Read

    Adding a New SSH Key in GitHub

    Updated:April 1, 20223 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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