Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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 :: php undefined function mysqli_fetch_all() 
Php :: wordpress wp_logout_url redirect 
Php :: carbon between hours 
Php :: advantages of php 
Php :: php arrow function 
Php :: laravel switch 
Php :: remove colon and white space in a string by php 
Php :: php find if string contains words from list index 
Php :: how get the photo size upload in laravel 
Php :: wp add menu page and subpage 
Php :: composer dump autoload laravel 
Php :: laravel image store 
Php :: php strlen 
Php :: php file_put_contents inode problem 
Php :: one lin if statement php 
Php :: how to clear php form data after submit 
Php :: php number format without rounding 
Php :: how to upgrade php in mac mojave 
Php :: laravel post ajax proper csrf 
Php :: if user name is wordpress 
Php :: PHP strtolower — Make a string lowercase 
Php :: laravel validation types 
Php :: how to add column to database in laravel 
Php :: get the number of affected rows in php using pdo update statement 
Php :: php execute command and display output 
Php :: read pdf text php 
Php :: how run all seeder at once in laravel 
Php :: php command get ini params 
Php :: php trim 
Php :: get number of days between two dates php 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =