3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // Surprise surprise! When the 2nd array param of array_diff() contains an elemant with value false, // the result will no longer contain null values. class foo { } //hio function myIsset($value) { return isset($value); } $array1 = array( 'null1' => null, 'null2' => null, 'bool' => true, ); $filtered_array1 = array_filter($array1, 'myIsset'); var_dump($array1, $filtered_array1, array_diff($array1, $filtered_array1)); $array2 = $array1; $array2['bool'] = false; $filtered_array2 = array_filter($array2, 'myIsset'); var_dump($array2, $filtered_array2, array_diff($array2, $filtered_array2));
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(3) { ["null1"]=> NULL ["null2"]=> NULL ["bool"]=> bool(true) } array(1) { ["bool"]=> bool(true) } array(2) { ["null1"]=> NULL ["null2"]=> NULL } array(3) { ["null1"]=> NULL ["null2"]=> NULL ["bool"]=> bool(false) } array(1) { ["bool"]=> bool(false) } array(0) { }