Answers for "php count key with same values"

PHP
3

php count array elements with specific key

$cnt = count(array_filter($array,function($element) {
  return $element['your_key']=='foo';
}));
Posted by: Guest on July-13-2020
0

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));
Posted by: Guest on October-28-2020

Code answers related to "php count key with same values"

Browse Popular Code Answers by Language