3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Given an array and a set of `old => new` keys, * will recursively replace all array keys that * are old with their corresponding new value. * * @param mixed $array * @param array $old_to_new_keys * * @return array */ function array_replace_keys($array, array $old_to_new_keys) { if(!is_array($array)){ return $array; } $temp_array = []; $ak = array_keys($old_to_new_keys); $av = array_values($old_to_new_keys); foreach($array as $key => $value){ if(array_search($key, $ak, true) !== false){ $key = $av[array_search($key, $ak)]; } if(is_array($value)){ $value = array_replace_keys($value, $old_to_new_keys); } $temp_array[$key] = $value; } return $temp_array; } $old = array( 'a' => 'blah', 'b' => 'key', 'c' => 'amazing', 'd' => array( 0 => 'want to replace', 1 => 'yes I want to' ) ); $replace = ["a" => "AA", 1 => 11]; var_export(array_replace_keys($old, $replace));

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.4.120.0110.00924.09
8.4.110.0090.01118.93
8.4.100.0140.00617.54
8.4.90.0120.00918.97
8.4.80.0070.00517.73
8.4.70.0070.01117.99
8.4.60.0070.00720.42
8.4.50.0050.00418.99
8.4.40.0070.01317.80
8.4.30.0100.01020.41
8.4.20.0120.00917.93
8.4.10.0060.00319.46
8.3.250.0120.00418.82
8.3.240.0110.00517.13
8.3.230.0120.00416.57
8.3.220.0060.00217.30
8.3.210.0070.00816.70
8.3.200.0110.00916.43
8.3.190.0110.00816.54
8.3.180.0100.00818.50
8.3.170.0160.00317.14
8.3.160.0100.01018.38
8.3.150.0070.01117.29
8.3.140.0080.00317.05
8.3.130.0040.00416.60
8.3.120.0030.00620.52
8.3.110.0060.00320.94
8.3.100.0130.00616.36
8.3.90.0110.00426.77
8.3.80.0030.00719.36
8.3.70.0110.00716.63
8.3.60.0120.00618.56
8.3.50.0100.00818.32
8.3.40.0100.00718.67
8.3.30.0040.01118.72
8.3.20.0040.00424.18
8.3.10.0040.00424.66
8.3.00.0040.00426.16
8.2.290.0130.00620.30
8.2.280.0110.01018.38
8.2.270.0070.01117.29
8.2.260.0090.00616.48
8.2.250.0000.00716.65
8.2.240.0160.00317.48
8.2.230.0100.00022.58
8.2.220.0040.00424.06
8.2.210.0070.00026.77
8.2.200.0100.00018.88
8.2.190.0040.01118.38
8.2.180.0220.00025.92
8.2.170.0120.00318.89
8.2.160.0110.00322.96
8.2.150.0050.00325.66
8.2.140.0050.00224.66
8.2.130.0000.00726.16
8.2.120.0000.00819.82
8.2.110.0030.00720.52
8.2.100.0000.01218.03
8.2.90.0080.00017.75
8.2.80.0000.00818.74
8.2.70.0040.00418.03
8.2.60.0000.00918.28
8.2.50.0040.00418.10
8.2.40.0040.00419.28
8.2.30.0040.00419.30
8.2.20.0070.00018.05
8.2.10.0070.00019.21
8.2.00.0000.00719.21
8.1.330.0100.00821.96
8.1.320.0130.00716.27
8.1.310.0150.00418.70
8.1.300.0050.00320.28
8.1.290.0040.00730.84
8.1.280.0100.00725.92
8.1.270.0100.00023.99
8.1.260.0080.00026.35
8.1.250.0000.00728.09
8.1.240.0070.00422.14
8.1.230.0040.00719.48
8.1.220.0000.00817.79
8.1.210.0040.00418.77
8.1.200.0040.00417.35
8.1.190.0030.00717.36
8.1.180.0000.00818.10
8.1.170.0060.00318.59
8.1.160.0040.00420.67
8.1.150.0040.00418.92
8.1.140.0040.00418.79
8.1.130.0000.00720.05
8.1.120.0040.00417.40
8.1.110.0000.00817.37
8.1.100.0000.00717.50
8.1.90.0000.00717.41
8.1.80.0000.00817.51
8.1.70.0000.01117.48
8.1.60.0040.00417.50
8.1.50.0040.00417.43
8.1.40.0040.00417.54
8.1.30.0040.00417.64
8.1.20.0000.00917.61
8.1.10.0040.00417.43
8.1.00.0040.00417.46
8.0.300.0040.00418.77
8.0.290.0000.00816.75
8.0.280.0040.00418.47
8.0.270.0060.00316.84
8.0.260.0070.00020.15
8.0.250.0040.00416.93
8.0.240.0000.00717.02
8.0.230.0000.00716.88
8.0.220.0070.00016.94
8.0.210.0000.00816.81
8.0.200.0000.00717.02
8.0.190.0000.00716.91
8.0.180.0040.00416.82
8.0.170.0060.00316.87
8.0.160.0070.00016.98
8.0.150.0040.00416.88
8.0.140.0070.00016.88
8.0.130.0030.00313.31
8.0.120.0040.00416.77
8.0.110.0030.00616.79
8.0.100.0050.00316.88
8.0.90.0070.00016.98
8.0.80.0100.00716.89
8.0.70.0050.00216.92
8.0.60.0040.00416.81
8.0.50.0040.00416.75
8.0.30.0070.00917.04
8.0.20.0110.00817.05
8.0.10.0140.00317.01
8.0.00.0110.00717.20
7.4.330.0020.00215.55
7.4.320.0000.00616.63
7.4.300.0000.00616.63
7.4.290.0040.00416.58
7.4.280.0040.00416.50
7.4.270.0070.00016.53
7.4.260.0000.00513.26
7.4.250.0000.00716.58
7.4.240.0000.00716.54
7.4.230.0000.00716.74
7.4.220.0020.00516.58
7.4.210.0070.01016.57
7.4.200.0030.00616.60
7.4.160.0090.00916.50
7.4.150.0110.00716.51
7.4.140.0070.01116.43
7.4.130.0200.00316.61
7.4.120.0100.00716.66
7.4.110.0130.00716.48
7.4.100.0070.00716.46
7.4.90.0040.01116.51
7.4.80.0090.00916.52
7.4.70.0070.01016.63
7.4.60.0080.01116.32
7.4.50.0100.01316.46
7.4.40.0090.00616.59
7.4.30.0100.01416.62
7.4.20.0150.00316.62
7.4.10.0090.01216.73
7.4.00.0140.00516.56
7.3.330.0040.00416.28
7.3.320.0030.00213.41
7.3.310.0000.00816.38
7.3.300.0080.00016.40
7.3.290.0110.00516.37
7.3.270.0060.00916.53
7.3.260.0110.00616.52
7.3.250.0070.01416.38
7.3.240.0090.01416.64
7.3.230.0040.01116.45
7.3.220.0130.00316.56
7.3.210.0100.00616.25
7.3.200.0140.00316.32
7.3.190.0040.01116.48
7.3.180.0040.01216.57
7.3.170.0060.01416.43
7.3.160.0090.01316.59
7.3.150.0110.00816.52
7.3.140.0080.01116.67
7.3.130.0060.01316.45
7.3.120.0120.00616.36
7.3.110.0120.00416.40
7.3.100.0120.00716.27
7.3.90.0110.00916.40
7.3.80.0130.00616.57
7.3.70.0060.01016.56
7.3.60.0130.00616.48
7.3.50.0120.01116.34
7.3.40.0090.01116.41
7.3.30.0030.01616.36
7.3.20.0170.00316.37
7.3.10.0100.01016.43
7.3.00.0160.00316.20

preferences:
30.48 ms | 403 KiB | 5 Q