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

php unique associative 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 :: remove comma in numeric in php 
Php :: laravel https assets 
Php :: beaver builder shortcode post title 
Php :: laravel migration price 
Php :: A table was not found You might have forgotten to run your migrations. You can run your migrations using php artisan migrate. Pressing the button below will try to run your migrations. 
Php :: get stock product woocommerce by id 
Php :: remove phpmyadmin ubuntu 20.04 completely 
Php :: In Connection.php line 664:SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema 
Php :: auth pages not getting css in laravel 
Php :: php get only numbers from string 
Php :: hide wordpress errors 
Php :: laravel insert or ignore 
Php :: generate random number of 4 digit in php 
Php :: remove add media button wordpress editor 
Php :: laravel validate number to be at least 3 digits 
Php :: string to slug php 
Php :: hashing passwords in yii 1 
Php :: wordpress PHPMailer config 
Php :: laravel time format 
Php :: php yesterday date 
Php :: php mysql connect 
Php :: parsefloat php 
Php :: pdo connexion 
Php :: preg_replace remove double quotes 
Php :: PHP wordwrap() Function 
Php :: get domain from subdomain php 
Php :: php get myme type of image 
Php :: PHP strncmp — Binary safe string comparison of the first n characters 
Php :: yii2 advanced nginx 
Php :: reindex array php 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =