3v4l.org

run code in 300+ PHP versions simultaneously
<?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)
8.3.40.0000.01518.84
8.3.30.0070.00720.17
8.3.20.0000.00820.38
8.3.10.0060.00321.97
8.3.00.0090.00022.45
8.2.170.0070.00722.96
8.2.160.0110.00322.12
8.2.150.0090.00024.18
8.2.140.0080.00024.66
8.2.130.0060.00326.16
8.2.120.0040.00420.87
8.2.110.0000.01121.03
8.2.100.0090.00317.91
8.2.90.0030.00618.00
8.2.80.0030.00519.05
8.2.70.0060.00318.05
8.2.60.0050.00317.75
8.2.50.0030.00617.88
8.2.40.0060.00320.07
8.2.30.0000.00819.48
8.2.20.0040.00417.71
8.2.10.0040.00417.86
8.2.00.0030.00617.84
8.1.270.0060.00323.90
8.1.260.0080.00026.35
8.1.250.0070.00028.09
8.1.240.0030.00622.33
8.1.230.0000.01121.10
8.1.220.0060.00318.01
8.1.210.0060.00318.77
8.1.200.0050.00317.48
8.1.190.0040.00417.55
8.1.180.0040.00818.10
8.1.170.0040.00418.71
8.1.160.0040.00418.88
8.1.150.0000.00818.67
8.1.140.0050.00317.49
8.1.130.0000.00717.84
8.1.120.0000.00817.56
8.1.110.0040.00417.55
8.1.100.0000.00717.45
8.1.90.0040.00417.54
8.1.80.0000.00717.61
8.1.70.0040.00417.58
8.1.60.0060.00317.70
8.1.50.0040.00417.53
8.1.40.0040.00417.64
8.1.30.0040.00417.75
8.1.20.0000.00817.73
8.1.10.0050.00517.61
8.1.00.0000.01017.55
8.0.300.0040.00418.77
8.0.290.0030.00617.00
8.0.280.0000.00818.56
8.0.270.0000.00717.28
8.0.260.0000.00716.94
8.0.250.0070.00016.98
8.0.240.0080.00016.96
8.0.230.0040.00417.09
8.0.220.0050.00316.90
8.0.210.0000.00716.89
8.0.200.0030.00316.95
8.0.190.0050.00317.05
8.0.180.0060.00317.02
8.0.170.0060.00317.05
8.0.160.0000.00717.08
8.0.150.0040.00416.93
8.0.140.0050.00317.02
8.0.130.0000.00613.43
8.0.120.0080.00016.96
8.0.110.0000.00716.99
8.0.100.0000.00817.13
8.0.90.0050.00316.85
8.0.80.0090.00616.96
8.0.70.0030.00616.89
8.0.60.0080.00017.06
8.0.50.0040.00416.89
8.0.30.0080.01117.15
8.0.20.0130.01117.40
8.0.10.0080.00017.08
8.0.00.0060.01216.74
7.4.330.0030.00315.00
7.4.320.0000.00716.57
7.4.300.0030.00316.67
7.4.290.0080.00016.63
7.4.280.0000.00716.70
7.4.270.0000.00816.73
7.4.260.0030.00313.44
7.4.250.0050.00216.73
7.4.240.0020.00516.76
7.4.230.0040.00416.53
7.4.220.0150.00616.75
7.4.210.0090.00716.69
7.4.200.0030.00416.72
7.4.190.0040.00416.87
7.4.160.0090.00916.66
7.4.150.0090.00917.40
7.4.140.0110.00617.86
7.4.130.0120.00516.69
7.4.120.0070.01116.57
7.4.110.0110.00716.60
7.4.100.0100.01016.59
7.4.90.0130.00616.50
7.4.80.0160.00619.39
7.4.70.0060.01216.54
7.4.60.0110.00816.39
7.4.50.0050.00516.61
7.4.40.0080.00322.77
7.4.30.0080.01716.61
7.4.00.0050.01214.97
7.3.330.0030.00313.45
7.3.320.0030.00313.43
7.3.310.0000.00716.25
7.3.300.0030.00316.50
7.3.290.0150.00616.47
7.3.280.0090.00616.47
7.3.270.0090.00917.40
7.3.260.0100.00716.38
7.3.250.0090.01116.63
7.3.240.0040.02116.67
7.3.230.0070.01116.50
7.3.210.0190.00616.79
7.3.200.0090.00919.39
7.3.190.0130.00916.57
7.3.180.0090.00816.54
7.3.170.0100.00716.48
7.3.160.0060.01216.54
7.3.120.0050.01214.91
7.3.110.0080.01215.13
7.3.100.0100.00715.00
7.3.90.0030.00615.03
7.3.80.0040.01114.87
7.3.70.0070.01015.09
7.3.60.0080.00415.05
7.3.50.0030.00714.99
7.3.40.0090.00014.77
7.3.30.0040.00815.09
7.3.20.0040.00416.56
7.3.10.0090.00616.56
7.3.00.0060.00916.56
7.2.330.0110.00816.95
7.2.320.0100.01016.74
7.2.310.0070.01216.68
7.2.300.0050.01416.73
7.2.290.0040.01216.82
7.2.250.0100.01015.07
7.2.240.0110.01115.12
7.2.230.0070.00415.15
7.2.220.0000.01515.16
7.2.210.0130.00315.09
7.2.200.0030.01015.36
7.2.190.0070.00315.16
7.2.180.0060.00615.23
7.2.170.0030.00914.96
7.2.00.0050.00519.53
7.1.330.0060.00615.93
7.1.320.0030.00615.61
7.1.310.0030.00715.79
7.1.300.0120.00415.80
7.1.290.0040.00816.02
7.1.280.0070.00415.84
7.1.270.0060.00315.85
7.1.260.0060.00915.87
7.1.100.0000.01118.24
7.1.70.0040.00717.27
7.1.60.0160.01019.32
7.1.50.0100.01416.89
7.1.00.0070.07722.44
7.0.200.0040.00416.77
7.0.140.0130.06322.18
7.0.100.0000.04720.14
7.0.90.0000.04320.04
7.0.80.0170.04320.04
7.0.70.0130.07719.97
7.0.60.0070.03719.98
7.0.50.0100.04320.45
7.0.40.0070.04320.09
7.0.30.0070.04020.07
7.0.20.0030.04320.13
7.0.10.0000.04720.00
7.0.00.0030.04320.18
5.6.280.0070.07321.05
5.6.250.0070.03720.64
5.6.240.0100.04720.56
5.6.230.0000.04720.77
5.6.220.0070.04020.70
5.6.210.0030.04720.61
5.6.200.0070.04021.00
5.6.190.0030.04321.06
5.6.180.0030.04321.07
5.6.170.0030.04321.16
5.6.160.0030.04321.16
5.6.150.0030.04321.17
5.6.140.0030.05721.00
5.6.130.0030.04321.18
5.6.120.0170.07721.07
5.6.110.0030.07721.01
5.6.100.0100.06321.00
5.6.90.0070.08721.08
5.6.80.0070.04020.40
5.6.70.0170.05020.51
5.6.60.0230.06020.46
5.6.50.0100.03320.49
5.6.40.0130.07320.54
5.6.30.0100.07720.52
5.6.20.0030.08020.54
5.6.10.0170.06720.45
5.6.00.0030.08320.33
5.5.380.0070.04020.61
5.5.370.0030.04020.40
5.5.360.0070.04020.39
5.5.350.0030.04320.53
5.5.340.0030.04320.82
5.5.330.0000.04320.82
5.5.320.0030.04320.95
5.5.310.0070.04020.92
5.5.300.0070.03720.82
5.5.290.0100.04320.82
5.5.280.0030.09320.93
5.5.270.0070.08020.95
5.5.260.0070.04720.81
5.5.250.0130.07720.73
5.5.240.0100.07720.32
5.5.230.0130.07020.36
5.5.220.0130.06320.23
5.5.210.0130.04320.24
5.5.200.0100.03320.24
5.5.190.0070.04020.16
5.5.180.0170.07020.30
5.5.160.0100.07020.32
5.5.150.0070.07720.23
5.5.140.0070.08020.32
5.5.130.0100.07720.18
5.5.120.0030.06020.34
5.5.110.0030.07720.30
5.5.100.0030.08020.16
5.5.90.0100.07720.13
5.5.80.0200.05720.13
5.5.70.0030.05720.15
5.5.60.0030.08020.15
5.5.50.0100.03320.17
5.5.40.0100.07320.12
5.5.30.0130.06720.11
5.5.20.0000.04320.14
5.5.10.0030.04020.11
5.5.00.0030.08020.14
5.4.450.0100.04319.38
5.4.440.0100.08019.28
5.4.430.0100.06719.46
5.4.420.0070.04019.46
5.4.410.0030.08019.07
5.4.400.0130.07319.18
5.4.390.0030.04719.21
5.4.380.0130.07019.04
5.4.370.0130.06019.09
5.4.360.0070.07018.86
5.4.350.0100.06318.95
5.4.340.0070.05019.25
5.4.320.0030.08019.24
5.4.310.0100.05718.91
5.4.300.0100.04019.15
5.4.290.0030.07719.17
5.4.280.0130.06719.14
5.4.270.0070.04719.20
5.4.260.0130.06019.14
5.4.250.0030.07318.86
5.4.240.0100.04318.84
5.4.230.0070.05718.84
5.4.220.0000.08719.04
5.4.210.0130.05719.15
5.4.200.0000.08019.23
5.4.190.0130.06319.03
5.4.180.0300.05018.84
5.4.170.0070.06719.13
5.4.160.0070.06019.03
5.4.150.0030.07318.83
5.4.140.0130.04716.45
5.4.130.0030.04016.50
5.4.120.0130.06716.35
5.4.110.0070.04016.39
5.4.100.0130.04316.53
5.4.90.0070.07316.38
5.4.80.0070.07016.54
5.4.70.0070.05716.41
5.4.60.0030.08016.54
5.4.50.0100.07016.46
5.4.40.0100.06716.39
5.4.30.0200.06016.38
5.4.20.0100.04716.44
5.4.10.0000.04016.51
5.4.00.0100.06315.64
5.3.290.0070.08714.69
5.3.280.0070.06714.75
5.3.270.0070.03714.73
5.3.260.0130.05014.63
5.3.250.0070.07014.72
5.3.240.0130.05714.69
5.3.230.0030.07714.77
5.3.220.0030.06314.79
5.3.210.0070.04014.61
5.3.200.0030.07314.65
5.3.190.0070.08014.78
5.3.180.0070.06714.79
5.3.170.0070.07014.63
5.3.160.0000.07714.63
5.3.150.0000.04714.71
5.3.140.0130.07014.67
5.3.130.0100.07314.71
5.3.120.0030.06314.59
5.3.110.0100.06014.59
5.3.100.0000.08714.18
5.3.90.0100.07014.14
5.3.80.0070.04314.12
5.3.70.0130.06314.18
5.3.60.0070.06713.99
5.3.50.0070.07013.97
5.3.40.0030.06013.97
5.3.30.0100.07014.07
5.3.20.0100.06013.92
5.3.10.0100.06713.64
5.3.00.0070.07313.67

preferences:
43.39 ms | 400 KiB | 5 Q