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

php get unique values by key from array

$array = array(
	array('group' => 'test', 'name' => 'Jane'),
    array('group' => 'test', 'name' => 'John'),
    array('group' => 'admin', 'name' => 'superadmin')
);
$unique_values_by_key = array_unique(array_column($array, 'group'));
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 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 :: php if $_post 
Php :: PHP mysqli_close function 
Php :: php exception import 
Php :: Theme and plugin editor in wp dashboard missing 
Php :: php iterate thru object 
Php :: no privileges to create databases phpmyadmin 
Php :: codeigniter 3 or where not in 
Php :: Syntax error or access violation: 1071 Specified key was too long; 
Php :: laravel get average from a column 
Php :: get absolute path php file 
Php :: for each php 
Php :: convert timestamp to date php 
Php :: php array filter 
Php :: string to boolean php 
Php :: php override trait method and call it 
Php :: what is the hashmap like in php 
Php :: redirect compact laravel 
Php :: artisan 
Php :: Append a text string to WooCommerce single product title 
Php :: carbon now 
Php :: How to check if email exists in laravel validaton 
Php :: Remove public from the url in the codeigniter 
Php :: migration laravel 
Php :: laravel checkbox checked 
Php :: wordpress logout 
Php :: Get current taxonomy term ID of the active page 
Php :: laravel target class does not exist 
Php :: next year php string 
Php :: how to get event dates on change in datetimepicker with laravel livewire 
Php :: filename php 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =