3v4l.org

run code in 300+ PHP versions simultaneously
<?php <?php function dive(array $map){ $columns = $tokens = array(); foreach($map as $key => $value){ if(is_array($value)){ // check for bool switch if(array_key_exists(0, $value)){ if($value[0] !== true) continue; $columns[$key] = $key; $tokens[$key] = $value[1]; }else{ // if another array recurse $tmp = dive($value); $columns = array_merge($columns, array_keys($tmp)); $tokens = array_merge($tokens, array_values($tmp)); } }else{ if(is_null($value)) continue; // catch non-null scalars $columns[$key] = $key; $tokens[$key] = "?"; } } // because $columns will inevitably contain duplicate values, once the // two arrays are combined, they will collapse/uniquify. #darkcorner return array_combine($columns, $tokens); } call_user_func(function(){ $a = array( "col1" => "val", "col2" => "val", "col3" => "val", "col4" => "val", ); $columns = array( "col1", "col2", "col3", "col4", ); $tokens = array( "?", "?", "?", "?", ); // list($c, $t) = dive($a); $tmp = dive($a); $c = array_keys($tmp); $t = array_values($tmp); if($columns == $c){ echo "TRUE\n"; } if($tokens == $t){ echo "TRUE\n"; } }); call_user_func(function(){ $a = array( "col1" => "val", "col2" => null, "col3" => "val", "col4" => "val", ); $columns = array( "col1", "col3", "col4", ); $tokens = array( "?", "?", "?", ); // list($c, $t) = dive($a); $tmp = dive($a); $c = array_keys($tmp); $t = array_values($tmp); if($columns == $c){ echo "TRUE\n"; } if($tokens == $t){ echo "TRUE\n"; } }); call_user_func(function(){ $a = array( "col1" => array(true, "val"), "col2" => array(true, "val"), "col3" => array(true, "val"), "col4" => array(true, "val"), ); $columns = array( "col1", "col2", "col3", "col4", ); $tokens = array( "val", "val", "val", "val", ); // list($c, $t) = dive($a); $tmp = dive($a); $c = array_keys($tmp); $t = array_values($tmp); if($columns == $c){ echo "TRUE\n"; } if($tokens == $t){ echo "TRUE\n"; } }); call_user_func(function(){ $a = array( "col1" => "val", "col2" => "val", "col3" => array(true, "val"), "col4" => array(true, "val"), ); $columns = array( "col1", "col2", "col3", "col4", ); $tokens = array( "?", "?", "val", "val", ); // list($c, $t) = dive($a); $tmp = dive($a); $c = array_keys($tmp); $t = array_values($tmp); if($columns == $c){ echo "TRUE\n"; } if($tokens == $t){ echo "TRUE\n"; } }); call_user_func(function(){ $a = array( "col1" => array(true, "val"), "col2" => array(true, "val"), "col3" => "val", "col4" => "val", ); $columns = array( "col1", "col2", "col3", "col4", ); $tokens = array( "val", "val", "?", "?", ); // list($c, $t) = dive($a); $tmp = dive($a); $c = array_keys($tmp); $t = array_values($tmp); if($columns == $c){ echo "TRUE\n"; } if($tokens == $t){ echo "TRUE\n"; } }); call_user_func(function(){ $a = array( "col1" => "val", "col2" => array(true, "val"), "col3" => array(true, "val"), "col4" => "val", ); $columns = array( "col1", "col2", "col3", "col4", ); $tokens = array( "?", "val", "val", "?", ); // list($c, $t) = dive($a); $tmp = dive($a); $c = array_keys($tmp); $t = array_values($tmp); if($columns == $c){ echo "TRUE\n"; } if($tokens == $t){ echo "TRUE\n"; } }); call_user_func(function(){ $a = array( array("col1" => "val"), array("col1" => "val"), array("col1" => "val"), array("col1" => "val"), ); $columns = array( "col1", ); $tokens = array( "?", ); // list($c, $t) = dive($a); $tmp = dive($a); $c = array_keys($tmp); $t = array_values($tmp); if($columns == $c){ echo "TRUE\n"; } if($tokens == $t){ echo "TRUE\n"; } }); call_user_func(function(){ $a = array( array("col1" => array(true, "val")), array("col1" => array(true, "val")), array("col1" => array(true, "val")), array("col1" => array(true, "val")), ); $columns = array( "col1", ); $tokens = array( "val", ); // list($c, $t) = dive($a); $tmp = dive($a); $c = array_keys($tmp); $t = array_values($tmp); if($columns == $c){ echo "TRUE\n"; } if($tokens == $t){ echo "TRUE\n"; } }); call_user_func(function(){ $a = array( array("col1" => array(true, "val"), "col2" => array(true, "val")), array("col1" => array(true, "val"), "col2" => array(true, "val")), array("col1" => array(true, "val"), "col2" => array(true, "val")), array("col1" => array(true, "val"), "col2" => array(true, "val")), ); $columns = array( "col1", "col2", ); $tokens = array( "val", "val", ); // list($c, $t) = dive($a); $tmp = dive($a); $c = array_keys($tmp); $t = array_values($tmp); if($columns == $c){ echo "TRUE\n"; } if($tokens == $t){ echo "TRUE\n"; } }); call_user_func(function(){ $a = array( array("col1" => "val", "col2" => "val"), array("col1" => "val", "col2" => "val"), array("col1" => "val", "col2" => "val"), array("col1" => "val", "col2" => "val"), ); $columns = array( "col1", "col2", ); $tokens = array( "?", "?", ); // list($c, $t) = dive($a); $tmp = dive($a); $c = array_keys($tmp); $t = array_values($tmp); if($columns == $c){ echo "TRUE\n"; } if($tokens == $t){ echo "TRUE\n"; } }); call_user_func(function(){ $a = array( array("col1" => "val", "col2" => null), array("col1" => "val", "col2" => null), array("col1" => "val", "col2" => null), array("col1" => "val", "col2" => null), ); $columns = array( "col1", ); $tokens = array( "?", ); // list($c, $t) = dive($a); $tmp = dive($a); $c = array_keys($tmp); $t = array_values($tmp); if($columns == $c){ echo "TRUE\n"; } if($tokens == $t){ echo "TRUE\n"; } }); call_user_func(function(){ $a = array( array("col1" => "val", "col2" => array(true, "val")), array("col1" => "val", "col2" => array(true, "val")), array("col1" => "val", "col2" => array(true, "val")), array("col1" => "val", "col2" => array(true, "val")), ); $columns = array( "col1", "col2", ); $tokens = array( "?", "val", ); // list($c, $t) = dive($a); $tmp = dive($a); $c = array_keys($tmp); $t = array_values($tmp); if($columns == $c){ echo "TRUE\n"; } if($tokens == $t){ echo "TRUE\n"; } }); call_user_func(function(){ $a = array( array("col1" => array(true, "val"), "col2" => "val"), array("col1" => array(true, "val"), "col2" => "val"), array("col1" => array(true, "val"), "col2" => "val"), array("col1" => array(true, "val"), "col2" => "val"), ); $columns = array( "col1", "col2", ); $tokens = array( "val", "?", ); // list($c, $t) = dive($a); $tmp = dive($a); $c = array_keys($tmp); $t = array_values($tmp); if($columns == $c){ echo "TRUE\n"; } if($tokens == $t){ echo "TRUE\n"; } });

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
5.4.240.0050.03812.38
5.4.230.0070.03612.37
5.4.220.0060.03612.37
5.4.210.0070.03512.37
5.4.200.0050.03812.37
5.4.190.0070.03512.36
5.4.180.0050.03612.36
5.4.170.0060.03612.37
5.4.160.0040.03812.36
5.4.150.0070.03512.36
5.4.140.0060.03812.05
5.4.130.0080.03412.03
5.4.120.0050.03512.00
5.4.110.0080.03511.99
5.4.100.0040.03712.00
5.4.90.0070.03611.99
5.4.80.0060.03711.99
5.4.70.0070.03311.99
5.4.60.0070.03411.99
5.4.50.0070.03411.99
5.4.40.0050.03511.98
5.4.30.0050.03811.97
5.4.20.0070.03811.97
5.4.10.0040.03611.98
5.4.00.0050.03611.47
5.3.280.0080.03612.71
5.3.270.0050.04212.72
5.3.260.0050.04312.72
5.3.250.0070.04312.72
5.3.240.0080.03912.72
5.3.230.0070.04212.71
5.3.220.0070.04312.68
5.3.210.0070.04112.68
5.3.200.0090.03512.68
5.3.190.0050.03912.68
5.3.180.0050.03912.67
5.3.170.0070.03812.67
5.3.160.0070.03612.67
5.3.150.0060.03812.67
5.3.140.0040.04112.66
5.3.130.0060.03812.65
5.3.120.0080.03912.66
5.3.110.0050.04312.66
5.3.100.0070.03812.12
5.3.90.0070.03812.08
5.3.80.0080.03412.07
5.3.70.0060.03712.08
5.3.60.0060.03812.06
5.3.50.0070.03712.00
5.3.40.0040.03912.00
5.3.30.0040.03811.94
5.3.20.0070.03811.71
5.3.10.0090.04311.67
5.3.00.0050.04611.66

preferences:
140.86 ms | 1394 KiB | 7 Q