Search
 
SCRIPT & CODE EXAMPLE
 

PHP

array_unique multidimensional php

<?php
    function super_unique($array,$key)
    {
       $temp_array = [];
       foreach ($array as &$v) {
           if (!isset($temp_array[$v[$key]]))
           $temp_array[$v[$key]] =& $v;
       }
       $array = array_values($temp_array);
       return $array;

    }


$arr="";
$arr[0]['id']=0;
$arr[0]['titel']="ABC";
$arr[1]['id']=1;
$arr[1]['titel']="DEF";
$arr[2]['id']=2;
$arr[2]['titel']="ABC";
$arr[3]['id']=3;
$arr[3]['titel']="XYZ";

echo "<pre>";
print_r($arr);
echo "unique*********************<br/>";
print_r(super_unique($arr,'titel'));

?>
Comment

get unique array from multidimentional array by value in php

$uniquePids = array_unique(array_map(function ($i) { return $i['pid']; }, $holder));
Comment

php unique associative nested 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 :: laravel blade upper case 
Php :: create slug with php 
Php :: larave artisan command run in web 
Php :: wp create user programmatically 
Php :: setinterval php 
Php :: laravel tinker generate password 
Php :: yum install php-mysql 
Php :: laravel in array blade 
Php :: create form request laravel 
Php :: how to get local current time in laravel 
Php :: laravel 404 
Php :: remove cache from cpanle larael 
Php :: php get current month first date 
Php :: php replace blackslash 
Php :: delete after 30 days in php 
Php :: php check request method 
Php :: dompdf laravel page break 
Php :: php remove anchor tag from string 
Php :: convert array to object php 
Php :: auth.php Class "AppUser" not found 
Php :: php check if headers already sent 
Php :: laravel reduce 
Php :: php curl_exec get response json 
Php :: create a wp plugin 
Php :: image store short method in laravel 
Php :: Exception #0 (MagentoFrameworkExceptionValidatorException): Invalid template file: 
Php :: bigtext migration laravel 
Php :: cambiar entre versiones de php linux 
Php :: laravel task scheduling command 
Php :: php must be an array or an object that implements Countable i 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =