3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $array=Array ( "21" => Array ( "0" => 3.5, "65" => Array ( "0" => 44.125 ), "150" => Array ( "0" => 15.25 ), "151" => Array ( "0" => 17.333333333333 ) ), "23" => Array ( "0" => 0, "166" => Array ( "0" => 26 ), "172" => Array ( "0" =>0 ), "182" => Array ( "0" => 20.333333333333 ), "183" => Array ( "0" => 24.125 ) ) ); $count1 = 0;$sum=0; $count2 = 0;$sum2=0; foreach ($array as $key3 => $value3) { if($key3 == "21") { foreach ($value3 as $key => $value) { if (strpos($key, '0') === 0) { $count1++;$sum=$sum+$value; } if(is_array($value)) { foreach($value as $key2=>$value2) { if(strpos($key2,'0') === 0) { $count1++ ;$sum=$sum+$value2; } } } } } if($key3 == "23") { foreach ($value3 as $key => $value) { if (strpos($key, '0') === 0) { $count2++;$sum2=$sum2+$value; } if(is_array($value)) { foreach($value as $key2=>$value2) { if(strpos($key2,'0') === 0) { $count2++; $sum2=$sum2+$value2; } } } } } } $array[21][0] = ($sum/$count1); $array[23][0] = ($sum2/$count2); print_r($array); echo $catCount = count(preg_grep("/^0+$/", array_keys(get_object_vars($array))));
Output for 5.3.0 - 7.1.0
Array ( [21] => Array ( [0] => 20.052083333333 [65] => Array ( [0] => 44.125 ) [150] => Array ( [0] => 15.25 ) [151] => Array ( [0] => 17.333333333333 ) ) [23] => Array ( [0] => 14.091666666667 [166] => Array ( [0] => 26 ) [172] => Array ( [0] => 0 ) [182] => Array ( [0] => 20.333333333333 ) [183] => Array ( [0] => 24.125 ) ) ) Warning: get_object_vars() expects parameter 1 to be object, array given in /in/Nu2F2 on line 101 Warning: array_keys() expects parameter 1 to be array, null given in /in/Nu2F2 on line 101 Warning: preg_grep() expects parameter 2 to be array, null given in /in/Nu2F2 on line 101 0
Output for 5.2.0 - 5.2.17
Array ( [21] => Array ( [0] => 20.052083333333 [65] => Array ( [0] => 44.125 ) [150] => Array ( [0] => 15.25 ) [151] => Array ( [0] => 17.333333333333 ) ) [23] => Array ( [0] => 14.091666666667 [166] => Array ( [0] => 26 ) [172] => Array ( [0] => 0 ) [182] => Array ( [0] => 20.333333333333 ) [183] => Array ( [0] => 24.125 ) ) ) Warning: array_keys(): The first argument should be an array in /in/Nu2F2 on line 101 Warning: preg_grep() expects parameter 2 to be array, null given in /in/Nu2F2 on line 101 0
Output for 4.3.11 - 5.1.6
Array ( [21] => Array ( [0] => 20.052083333333 [65] => Array ( [0] => 44.125 ) [150] => Array ( [0] => 15.25 ) [151] => Array ( [0] => 17.333333333333 ) ) [23] => Array ( [0] => 14.091666666667 [166] => Array ( [0] => 26 ) [172] => Array ( [0] => 0 ) [182] => Array ( [0] => 20.333333333333 ) [183] => Array ( [0] => 24.125 ) ) ) Warning: array_keys(): The first argument should be an array in /in/Nu2F2 on line 101 Warning: preg_grep(): Second argument to preg_grep() should be an array in /in/Nu2F2 on line 101 0
Output for 4.3.2 - 4.3.10
Array ( [21] => Array ( [0] => 20.052083333333 [65] => Array ( [0] => 44.125 ) [150] => Array ( [0] => 15.25 ) [151] => Array ( [0] => 17.333333333333 ) ) [23] => Array ( [0] => 14.091666666667 [166] => Array ( [0] => 26 ) [172] => Array ( [0] => 0 ) [182] => Array ( [0] => 20.333333333333 ) [183] => Array ( [0] => 24.125 ) ) ) Warning: array_keys(): The first argument should be an array in /in/Nu2F2 on line 101 Warning: Second argument to preg_grep() should be an array in /in/Nu2F2 on line 101 0
Output for 4.3.0 - 4.3.1
Array ( [21] => Array ( [0] => 20.052083333333 [65] => Array ( [0] => 44.125 ) [150] => Array ( [0] => 15.25 ) [151] => Array ( [0] => 17.333333333333 ) ) [23] => Array ( [0] => 14.091666666667 [166] => Array ( [0] => 26 ) [172] => Array ( [0] => 0 ) [182] => Array ( [0] => 20.333333333333 ) [183] => Array ( [0] => 24.125 ) ) ) Warning: array_keys() [http://www.php.net/function.array-keys]: The first argument should be an array in /in/Nu2F2 on line 101 Warning: Second argument to preg_grep() should be an array in /in/Nu2F2 on line 101 0