Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Programming»PHP»How to Remove Duplicate Array Values in PHP

    How to Remove Duplicate Array Values in PHP

    By RahulNovember 26, 20201 Min Read

    A Sample PHP script to remove all the duplicate values from an array. A running example to remove duplicate array values using PHP

    Advertisement

    Use PHP array_unique() function to remove all the duplicate values form an array. This function takes input of an array and return another array without duplicate values.

    Here is an sample example:

    1
    2
    3
    4
    5
    6
    7
    <?php
    $input = array("a" => "green", "green", "blue", "b" => "green", "red");
    // Remove duplicate elements from an array
    $result = array_unique($array);
    print_r($result);
    ?>

    Expected output:

    Array
    (
        [a] => green
        [1] => blue
        [2] => red
    )
    

    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

    Installing PHP on Pop!_OS

    How to Install PHP 8.x on Pop!_OS

    Managing Dependencies with Composer: A Beginner’s Guide

    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.