Remove Duplicate elements from array in php

 <?php

$duplicate = array(4,8,4,3,8,5,2,4,5,9,7,6,9);

$length =  count($duplicate);

$unique = array();


foreach($duplicate as $value){

if(!in_array($value,$unique)){

$unique[] = $value;

}

}

echo"<pre>";

print_r($unique);

?>

Output:-

Array
(
    [0] => 4
    [1] => 8
    [2] => 3
    [3] => 5
    [4] => 2
    [5] => 9
    [6] => 7
    [7] => 6
)

Comments

Popular posts from this blog

Add Css And Js Files on Specific Page In laravel

Be 10x 10 tools from sessions

Diffrence between Put and Patch