An array of 2000 data entries and an index with duplicate values. for example, an array contains ,............... the repeat indexes, 14 & nbsp; 5, 15 & nbsp ;.... it cannot be a two-for or while loop, which is too costly. ----- an array of 2000 data records, and an index with duplicate values is found.
For example, an array contains ,...............
Obtain 2 duplicate indexes, 2, 3, 10, 11, and 14.
5 duplicate indexes 7, 8, 15
....
It cannot be a two-for or while loop, which is too costly.
------ Solution --------------------
PHP code
$ Arr = array (,); $ tmp = array (); foreach ($ arr AS $ k =>v v) {if (isset ($ tmp [$ v]) {if ($ tmp [$ v]) {$ tmp [$ v]. = "," ;}$ tmp [$ v]. = $ k;} else {$ tmp [$ v] = "" ;}} foreach ($ tmp AS $ k => $ v) {if ($ v) {echo $ k, "=>", $ v, "\ n" ;}} unset ($ tmp );
------ Solution --------------------
PHP code
$ A = array (,); $ r = array (); foreach ($ a as $ v) {if (isset ($ r [$ v]) continue; if ($ t = array_keys (array_intersect ($ a, array ($ v )))) {unset ($ t [0]); $ r [$ v] = join (',', $ t) ;}$ r = array_diff ($ r, array (''); print_r ($ r );
------ Solution --------------------
PHP code
$arr = array(1,2,2,2,3,4,5,5,5,6,2,2,7,8,2,5,3,9);$str = implode(',', $arr);foreach ($arr as $k=>$v){ $t[$v] .= !isset($t[$v]) ? '' : $k . ','; $l += strlen($v); if((strrpos($str, $v.'')) == $l-strlen($v)) $t[$v] = trim($t[$v], ','); ++$l;}print_r($t);