Search
 
SCRIPT & CODE EXAMPLE
 

PHP

array_unique


<?php
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);
?>

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

array unique php

<?php
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);
?>
Comment

array unique php

<?php
    // Syntax: array_unique(array $array, int $flags = SORT_STRING): array
    // Desc: Removes duplicate values from an array
    $arr = Array("red", "red", "green", "blue", "blue", "white");
    echo "<pre>";
    print_r($arr);
    echo "</pre> <br><br>";
    
    $arrUnique = array_unique($arr);

    echo "<pre>";
    print_r($arrUnique);
    echo "</pre> <br><br>";

    /* -------- output -----------
    Array
    (
        [0] => red
        [1] => red
        [2] => green
        [3] => blue
        [4] => blue
        [5] => white
    )
    
    Array
    (
        [0] => red
        [2] => green
        [3] => blue
        [5] => white
    )
    */
?>
Comment

unique key value array php

$input = array_map("unserialize", array_unique(array_map("serialize", $input)));
Comment

php unique assoc array by value

<?php
    function uniquAsoc($array,$key){
        $resArray=[];
        foreach($array as $val){
          if(empty($resArray)){
            array_push($resArray,$val);
          }else{
            $value=array_column($resArray,$key);
            if(!in_array($val[$key],$value)){
                array_push($resArray,$val);
              }
          }          
        }
        
        return $resArray;
    }
$array=[['phone'=>123,'id'=>1],['phone'=>748,'id'=>1],['phone'=>958,'id'=>3]];
print_r(uniquAsoc($array,'id')); 
/*
Array
(
    [0] => Array
        (
            [phone] => 123
            [id] => 1
        )

    [1] => Array
        (
            [phone] => 958
            [id] => 3
        )

)
  */
?>
Comment

PREVIOUS NEXT
Code Example
Php :: destroy multiple sessions in laravel 
Php :: php quotations within quotations 
Php :: php super 
Php :: php octal to decimal 
Php :: convert datetime to string in php 
Php :: install php 7.1 on ubuntu 18.04 
Php :: if request type is post 
Php :: today date to ago for the date in php 
Php :: laravel start que listener 
Php :: laravel get all old input 
Php :: add two numbers in php 
Php :: return with success message laravel 
Php :: maatwebsite/excel package 5.2 laravel 
Php :: wordpress send reset password link inside wp_new_user_notification_email 
Php :: class php 
Php :: laravel trans with parameters 
Php :: laravel file custom name 
Php :: How to add custom button in wordpress admin section 
Php :: laravel 8 add column to existing table 
Php :: laravel request has 
Php :: php sort array remove keys 
Php :: laravel validation string type 
Php :: php class file upload 
Php :: wordpress create comment programmatically 
Php :: IlluminateContractsContainerBindingResolutionException 
Php :: group_concat mysql limit issue 
Php :: php key value array to string 
Php :: secure random number php 
Php :: php slice array by key 
Php :: how-to-generate-an-xlsx-using-php 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =