3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ 2 => [ 3, ], 3 => [ 8, ], 4 => [ 5, ], 5 => [ 8, ], 6 => [ 3, 8, ], 7 => [ 2, 5, ], 8 => [ 3, 8, ], ]; $occurrences = []; $mapped = array_map(function (array $values) use (&$occurrences) { $index = serialize($values); if (!array_key_exists($index, $occurrences)) { $occurrences[$index] = 1; return 0; } $occurrences[$index]++; return $occurrences[$index] - 1; }, $data); var_dump($mapped);

preferences:
32.55 ms | 406 KiB | 5 Q