3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $temp = array ( 0 => array( 0 => "a" ), 1 => array( 0 => "b", 1 => "c" ), "a" => array( "b" => "d" ) ); echo "<pre>"; print_r($arr); $new_arr = array(); foreach ($temp as $key => $value) { if(count($value)>1) $new_arr[$key] = $value; else { $new_arr[$key] = $value[0]; } } print_r($new_arr);
based on Qmb5J
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.3.0rc3
<pre> Notice: Undefined variable: arr in /in/3EfEN on line 15 Notice: Undefined offset: 0 in /in/3EfEN on line 23 Array ( [0] => a [1] => Array ( [0] => b [1] => c ) [a] => )
Output for hhvm-3.12.14 - 3.17.3
<pre> Notice: Undefined variable: arr in /in/3EfEN on line 15 Notice: Undefined index: 0 in /in/3EfEN on line 23 Array ( [0] => a [1] => Array ( [0] => b [1] => c ) [a] => )