3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $u = []; $a = [0, 1, 2, 0, 1, 2]; foreach ($a as $v) { if (isset($u[$v])) { continue; } $u[$v] = array_keys($a, $v); } var_dump($u);
based on MtIgQ
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.0
array(3) { [0]=> array(2) { [0]=> int(0) [1]=> int(3) } [1]=> array(2) { [0]=> int(1) [1]=> int(4) } [2]=> array(2) { [0]=> int(2) [1]=> int(5) } }