Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php $myarray = Array("2011-06-21", "2011-06-22", "2011-06-22", "2011-06-23", "2011-06-23", "2011-06-24", "2011-06-24", "2011-06-25", "2011-06-25", "2011-06-26"); print_r(get_keys_for_duplicate_values($myarray));die(); function get_keys_for_duplicate_values($my_arr, $clean = false) { if ($clean) { return array_unique($my_arr); } $dups = $new_arr = array(); foreach ($my_arr as $key => $val) { if (!isset($new_arr[$val])) { $new_arr[$val] = $key; } else { if (isset($dups[$val])) { $dups[$val][] = $key; } else { $dups[$val] = array($key); // Comment out the previous line, and uncomment the following line to // include the initial key in the dups array. // $dups[$val] = array($new_arr[$val], $key); } } } return $dups; }
Copy Clear