Search
 
SCRIPT & CODE EXAMPLE
 

PHP

get duplicate value from array php

$arr = array(1, 4, 6, 1, 8, 9, 4, 6);

$unique = array_unique($arr);

$duplicates = array_diff_assoc($arr, $unique);

print_r($duplicates);
Array ( [3] => 1 [6] => 4 [7] => 6 )
Comment

php get keys of duplicate values in array

<?php
/** 
	Examples of these functions:
	array_unique, 
    array_diff_assoc, 
    array_diff, 
    array_keys, 
    array_intersect 
    
    Examle with an array: 
*/
$array = array('a', 'a', 'b', 'c', 'd');

// Unique values
$unique = array_unique($array);

// Duplicates
$duplicates = array_diff_assoc($array, $unique);

// Unique values
$result = array_diff($unique, $duplicates);

// Get the unique keys
$unique_keys = array_keys($result);

// Get duplicate keys
$duplicate_keys = array_keys(array_intersect($array, $duplicates));
Comment

php get duplicate keys in array without using inbuilt function

$arr = array(3,5,2,5,3,9);
foreach($arr as $key => $val){
  //remove the item from the array in order 
  //to prevent printing duplicates twice
  unset($arr[$key]); 
  //now if another copy of this key still exists in the array 
  //print it since it's a dup
  if (in_array($val,$arr)){
    echo $val . " ";
  }
}
Comment

PREVIOUS NEXT
Code Example
Php :: laravel wheredate 
Php :: reply to wp_mail 
Php :: print in php 
Php :: laravel get column field name 
Php :: zip missing php install 
Php :: Clear and delete the folder after the time specified in php 
Php :: how to add page link in laravel 
Php :: php add element to beginning of associative array 
Php :: eloquent get trashed record 
Php :: withdefault laravel 
Php :: how hide empty category woocommerce wordpress 
Php :: grouping routes based on controller 
Php :: difference between use and require in php 
Php :: where condition in array in codeigniter 
Php :: woocommerce change add to cart button text 
Php :: laravel create model 
Php :: remove special characters in php 
Php :: php print datetime 
Php :: laravel check if email is real 
Php :: multiple submit button in php 
Php :: enqueue css 
Php :: php error check 
Php :: wordpress how to match password 
Php :: How To Unset Or Delete An Element From Array By Value In PHP? 
Php :: php quotations within quotations 
Php :: laravel migrations rename table 
Php :: laravel foreach loop index in controller 
Php :: @lang laravel blade 
Php :: .htaccess Prevent access to php.ini 
Php :: php split string 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =