3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $output = array(); foreach($your_array as $key => $current) { if( !array_key_exists($current, $output) ) { // create new entry $output[$current] = array( $key ); } else { // add to existing entry $output[$current][] = $key; } } print_r($output); ?>
Output for 5.1.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined variable: your_array in /in/LgTcK on line 4 Warning: Invalid argument supplied for foreach() in /in/LgTcK on line 4 Array ( )
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined variable: your_array in /in/LgTcK on line 12 Warning: Invalid argument supplied for foreach() in /in/LgTcK on line 12 Array ( )
Output for 4.3.0 - 4.3.10, 4.4.0 - 5.0.5
Warning: Invalid argument supplied for foreach() in /in/LgTcK on line 4 Array ( )
Output for 4.3.11
Array ( )