PHP - check that a value is not showing twice in an array
2 answers
$dupe = 0;
foreach($yourarray as $key => $val) {
if(array_key_exists($seen, $val['language'])) {
// a duplicate exists!
$dupe = 1;
// could do other stuff here too if you want,
// like if you want to know the $key with the dupe
// if all you care about is whether or not any dupes
// exist, you could use a "break;" here to early-exit
// for efficiency. To find all dupes, don't use break.
}
$seen[$val['language']] = 1;
}
// If $dupe still = 0 here, then no duplicates exist.
+3
a source to share
Tried PHP array_unique function ?
(Read the user comments / notes below, especially the one made by regede in inbox dot ru which made a recursive function for multidimensional arrays)
+1
a source to share