3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* PathArray enables working on 'dot notation' like: $data = ['user' => ['name' => 'John', 'sex' => 'male'] ], echo PathArray::get($data, 'user.name');// (We can use different separators than '.') More example usages below the class. */ class PathArray { /* Used mostly internally, will return keys - that is, if 'path' is already an array, it will return it. if it's a string it will explode it by $separator */ public static function pathKeys ($path, $separator = '.'){ if(is_array($path)){ return $path; } return explode($separator,$path); } /* @param string|array $path a string like node1.node2.node3 or an array with keys. */ public static function exists(array $data, $path){ $result = $data; foreach(self::pathKeys($path) as $key) { if(!isset($result[$key])){ return false; } $result = $result[$key]; } return true; } /* example: PathArray::get($data, 'user.name'));//'John' @param string|array $path a string like node1.node2.node3 or an array with keys. */ public static function get(array $data, $path, $default = NULL){ $result = $data; foreach(self::pathKeys($path) as $key) { if(!isset($result[$key])){ return $default; } $result = $result[$key]; } return $result; } /* Creates a new key - value, or modifies an existing one. @param string|array $path a string like node1.node2.node3 or an array with keys. */ public static function set(array &$data, $path, $val){ $result = &$data; foreach(self::pathKeys($path) as $key) { $result = &$result[$key]; } $result = $val; return $data; } } //Example usage //Some sample data. $data = [ 'user' => ['name' => 'John', 'sex' => 'male', 'children' => ['Mary', 'Robert'] ], 'file' => ['name' => 'funny_cat'] ]; echo "--------------------::exists tests \n"; var_dump(PathArray::exists($data, 'user.name'));//true var_dump(PathArray::exists($data, 'nonexisting'));//false echo "--------------------::get tests \n"; var_dump(PathArray::get($data, 'user.name'));//'John' var_dump(PathArray::get($data, PathArray::pathKeys('user/name','/')));//different separator, also returns 'John' var_dump(PathArray::get($data, 'user.children'));//an array with two values, Mary, Robert var_dump(PathArray::get($data, 'user.children.0'));//Mary var_dump(PathArray::get($data, 'user.children.10'));//doesn't exist, default value returned (in this case - null) echo "--------------------::set tests \n"; PathArray::set($data, 'file.name', 'funny_dog');//we change existing "funny_cat" to "funny_dog" PathArray::set($data, 'file.size', '1000');//we set a new key and value var_dump($data);

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.5.10.0110.00516.82
8.5.00.0120.01020.02
8.4.160.0120.01322.30
8.4.150.0020.00114.05
8.4.140.0090.01217.65
8.4.130.0090.01118.03
8.4.120.0130.00620.47
8.4.110.0140.00522.29
8.4.100.0130.00617.84
8.4.90.0110.00919.05
8.4.80.0100.00317.70
8.4.70.0110.01117.71
8.4.60.0160.00618.88
8.4.50.0050.00419.52
8.4.40.0070.01417.77
8.4.30.0120.00819.68
8.4.20.0060.01519.53
8.4.10.0130.00319.65
8.3.280.0100.00918.63
8.3.270.0120.00916.44
8.3.260.0040.00416.86
8.3.250.0120.00718.92
8.3.240.0130.00716.40
8.3.230.0120.00816.36
8.3.220.0130.00617.09
8.3.210.0100.00916.85
8.3.200.0040.00516.92
8.3.190.0100.00817.28
8.3.180.0080.00616.54
8.3.170.0160.00019.00
8.3.160.0090.00016.48
8.3.150.0120.00620.67
8.3.140.0100.01016.76
8.3.130.0000.00816.60
8.3.120.0030.00619.14
8.3.110.0080.00020.94
8.3.100.0100.00018.35
8.3.90.0000.00816.75
8.3.80.0030.00618.43
8.3.70.0070.01116.63
8.3.60.0110.00418.43
8.3.50.0050.00916.65
8.3.40.0130.00318.73
8.3.30.0120.00318.58
8.3.20.0030.00621.77
8.3.10.0040.00423.48
8.3.00.0090.00023.71
8.2.290.0100.00920.67
8.2.280.0070.00118.80
8.2.270.0110.00718.97
8.2.260.0080.00020.29
8.2.250.0030.00516.95
8.2.240.0030.00617.22
8.2.230.0040.00422.58
8.2.220.0080.00024.06
8.2.210.0120.00626.77
8.2.200.0070.00318.41
8.2.190.0140.00016.58
8.2.180.0070.01516.60
8.2.170.0090.00622.96
8.2.160.0080.00819.91
8.2.150.0030.00624.18
8.2.140.0080.00024.66
8.2.130.0040.00420.68
8.2.120.0030.00626.35
8.2.110.0070.00322.22
8.2.100.0040.00717.91
8.2.90.0040.00417.88
8.2.80.0050.00318.77
8.2.70.0080.00017.93
8.2.60.0040.00417.63
8.2.50.0040.00418.22
8.2.40.0030.00520.59
8.2.30.0040.00420.54
8.2.20.0040.00418.04
8.2.10.0000.00818.16
8.2.00.0040.00418.04
8.1.330.0110.00722.12
8.1.320.0130.00616.05
8.1.310.0120.00616.64
8.1.300.0000.00916.39
8.1.290.0070.00318.88
8.1.280.0120.00325.92
8.1.270.0080.00022.14
8.1.260.0080.00026.35
8.1.250.0050.00328.09
8.1.240.0060.00322.16
8.1.230.0070.00719.61
8.1.220.0000.00917.77
8.1.210.0050.00318.77
8.1.200.0030.00517.35
8.1.190.0040.00417.22
8.1.180.0050.00318.10
8.1.170.0030.00518.61
8.1.160.0040.00418.92
8.1.150.0050.00220.30
8.1.140.0050.00217.74
8.1.130.0050.00319.05
8.1.120.0050.00217.55
8.1.110.0050.00317.47
8.1.100.0050.00317.55
8.1.90.0070.00017.46
8.1.80.0030.00517.50
8.1.70.0040.00417.38
8.1.60.0080.00017.59
8.1.50.0070.00717.52
8.1.40.0040.00417.54
8.1.30.0000.00917.68
8.1.20.0040.00417.63
8.1.10.0000.00817.66
8.1.00.0030.00517.59
8.0.300.0040.00420.10
8.0.290.0040.00416.75
8.0.280.0040.00418.36
8.0.270.0030.00316.80
8.0.260.0030.00316.86
8.0.250.0040.00417.09
8.0.240.0050.00317.09
8.0.230.0030.00616.97
8.0.220.0070.00017.04
8.0.210.0000.00716.86
8.0.200.0040.00416.95
8.0.190.0000.00717.02
8.0.180.0000.00716.95
8.0.170.0000.00817.00
8.0.160.0060.00316.99
8.0.150.0050.00216.90
8.0.140.0000.00716.97
8.0.130.0000.00613.46
8.0.120.0080.00016.84
8.0.110.0000.00916.96
8.0.100.0080.00016.94
8.0.90.0040.00417.01
8.0.80.0030.01216.96
8.0.70.0070.00016.88
8.0.60.0080.00016.79
8.0.50.0000.00716.86
8.0.30.0100.00917.15
8.0.20.0090.01317.40
8.0.10.0040.00416.99
8.0.00.0140.00516.90
7.4.330.0050.00015.55
7.4.320.0000.00616.62
7.4.300.0000.00716.59
7.4.290.0070.00416.46
7.4.280.0040.00416.61
7.4.270.0030.00316.67
7.4.260.0060.00616.62
7.4.250.0090.00016.57
7.4.240.0050.00316.65
7.4.230.0070.00016.75
7.4.220.0080.00016.54
7.4.210.0090.00716.62
7.4.200.0040.00416.55
7.4.160.0100.00616.60
7.4.140.0110.00717.86
7.4.130.0060.01516.58
7.4.120.0100.01016.50
7.4.110.0040.01316.53
7.4.100.0090.01216.48
7.4.90.0100.01416.47
7.4.80.0080.01719.39
7.4.70.0070.01416.71
7.4.60.0080.01116.43
7.4.50.0060.01216.40
7.4.40.0070.01016.68
7.4.00.0130.00314.66
7.3.330.0030.00313.46
7.3.320.0030.00313.22
7.3.310.0030.00316.29
7.3.300.0050.00316.23
7.3.290.0110.00316.38
7.3.280.0160.00616.34
7.3.260.0120.00916.43
7.3.250.0130.00616.37
7.3.240.0110.00716.61
7.3.230.0100.01316.61
7.3.210.0030.01216.59
7.3.200.0100.01316.64
7.3.190.0240.00316.57
7.3.180.0060.01016.57
7.3.170.0070.01116.55
7.3.160.0140.00316.31
7.3.120.0000.01414.99
7.3.110.0000.01414.71
7.3.100.0030.01414.74
7.3.90.0060.00614.57
7.3.80.0120.00414.93
7.3.70.0030.01414.99
7.3.60.0040.00915.03
7.3.50.0000.01414.86
7.3.40.0030.01315.00
7.3.30.0040.00714.67
7.3.20.0160.00016.48
7.3.10.0090.00616.93
7.3.00.0080.00316.72
7.2.330.0130.00416.76
7.2.320.0100.01316.70
7.2.310.0070.01716.52
7.2.300.0090.01216.74
7.2.290.0130.00516.59
7.2.240.0100.00615.10
7.2.230.0110.00714.95
7.2.220.0090.00614.94
7.2.210.0030.01315.02
7.2.200.0060.01015.03
7.2.190.0070.01115.10
7.2.180.0090.00614.95
7.2.170.0030.01315.03
7.2.160.0090.00614.97
7.2.150.0040.01116.74
7.2.140.0090.00616.82
7.2.130.0100.00716.92
7.2.120.0070.00717.00
7.2.110.0090.00316.96
7.2.100.0060.00917.02
7.2.90.0040.01216.91
7.2.80.0070.01016.99
7.2.70.0120.00317.14
7.2.60.0070.00916.82
7.2.50.0000.01616.96
7.2.40.0060.00916.69
7.2.30.0100.01218.86
7.2.20.0100.00918.12
7.2.10.0140.00818.18
7.2.00.0090.01418.51
7.1.330.0070.01015.50
7.1.320.0030.01215.70
7.1.310.0070.00715.79
7.1.300.0000.01315.85
7.1.290.0070.00315.82
7.1.280.0080.00815.59
7.1.270.0030.00715.86
7.1.260.0030.01015.63
7.1.250.0060.01215.74
7.1.200.0000.01415.86
7.1.150.0130.01718.36
7.1.140.0090.01918.41
7.1.130.0140.01718.27
7.1.120.0120.01518.46
7.1.110.0140.01617.57
7.1.100.0050.01718.11
7.1.90.0120.01218.37
7.1.80.0110.01018.21
7.1.70.0090.01316.92
7.1.60.0350.01535.15
7.1.50.0350.01834.93
7.1.40.0360.01934.33
7.1.30.0300.01934.48
7.1.20.0330.02034.55
7.1.10.0070.01416.81
7.1.00.0110.01116.43

preferences:
166.65 ms | 403 KiB | 5 Q