3v4l.org

run code in 300+ PHP versions simultaneously
<?php class KeysReplacer { public $default = [ 'id' => 'id', 'full_address' => 'adress', 'floorall' => 'floorall', 'build_year' => 'build_year', ]; public $services = [ 'service_1' => [ 'id' => 'internal_id', 'full_address' => 'locality', 'floorall' => 'floorall', 'build_year' => 'build_date' ], 'service_2' => [ 'id' => 'ид', 'full_address' => 'полный_адрес', 'floorall' => 'этажность', 'build_year' => 'год_постройки' ], ]; public function __invoke($item, $from = null) { $result = []; foreach($item as $key => $value){ $result[$from && isset($this->services[$from][$key]) ? $this->services[$from][$key] : $this->default[$key]] = $value; } return json_encode($result, JSON_UNESCAPED_UNICODE); } } function getItem(){ return [ 'id' => 1, 'full_address' => 'г. Москва', 'floorall' => 18, 'build_year' => 1990 ]; } $item = getItem(); $responseNormalizer = new KeysReplacer; $response_0 = $responseNormalizer($item); $response_1 = $responseNormalizer($item, 'service_1'); $response_2 = $responseNormalizer($item, 'service_2'); var_dump($response_0); // string(68) "{"id":1,"adress":"г. Москва","floorall":18,"build_year":1990}" var_dump($response_1); // string(79) "{"internal_id":1,"locality":"г. Москва","floorall":18,"build_date":1990}" var_dump($response_2); // string(112) "{"ид":1,"полный_адрес":"г. Москва","этажность":18,"год_постройки":1990}"

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.60.0120.00318.33
8.3.50.0110.00616.28
8.3.40.0070.00718.98
8.3.30.0040.01118.84
8.3.20.0070.00724.18
8.3.10.0040.00424.66
8.3.00.0040.00426.16
8.2.180.0110.01125.92
8.2.170.0110.01118.96
8.2.160.0090.00922.96
8.2.150.0040.00425.66
8.2.140.0060.00324.66
8.2.130.0050.00326.16
8.2.120.0040.00419.95
8.2.110.0060.00321.08
8.2.100.0070.00417.91
8.2.90.0080.00018.03
8.2.80.0050.00317.97
8.2.70.0000.00817.93
8.2.60.0030.00618.12
8.2.50.0080.00018.10
8.2.40.0060.00321.05
8.2.30.0040.00418.12
8.2.20.0000.00717.99
8.2.10.0070.00019.31
8.2.00.0040.00719.42
8.1.280.0170.00725.92
8.1.270.0080.00023.99
8.1.260.0090.00026.35
8.1.250.0060.00328.09
8.1.240.0090.00022.54
8.1.230.0040.00722.17
8.1.220.0030.00617.79
8.1.210.0030.00618.86
8.1.200.0040.00417.35
8.1.190.0050.00318.97
8.1.180.0040.00418.10
8.1.170.0050.00318.49
8.1.160.0040.00418.73
8.1.150.0000.00718.87
8.1.140.0040.00420.58
8.1.130.0040.00417.46
8.1.120.0080.00017.42
8.1.110.0030.00617.33
8.1.100.0050.00217.41
8.1.90.0040.00417.36
8.1.80.0030.00317.48
8.1.70.0000.00717.48
8.1.60.0040.00417.63
8.1.50.0030.00517.57
8.1.40.0000.00817.39
8.1.30.0040.00417.63
8.1.20.0040.00417.65
8.1.10.0040.00417.50
8.1.00.0030.00617.54
8.0.300.0070.00019.86
8.0.290.0060.00316.75
8.0.280.0080.00018.38
8.0.270.0000.00717.94
8.0.260.0030.00316.69
8.0.250.0000.00716.83
8.0.240.0000.00716.84
8.0.230.0000.00716.84
8.0.220.0020.00516.76
8.0.210.0020.00516.75
8.0.200.0030.00316.95
8.0.190.0000.00816.93
8.0.180.0070.00016.92
8.0.170.0050.00516.93
8.0.160.0040.00416.81
8.0.150.0000.00716.67
8.0.140.0040.00416.89
8.0.130.0050.00013.34
8.0.120.0030.00516.86
8.0.110.0040.00416.89
8.0.100.0050.00216.84
8.0.90.0040.00416.83
8.0.80.0100.00816.88
8.0.70.0000.00816.68
8.0.60.0070.00016.77
8.0.50.0000.00716.83
8.0.30.0130.00417.27
8.0.20.0120.00617.02
8.0.10.0180.00317.19
8.0.00.0120.00916.98
7.4.330.0020.00215.55
7.4.320.0000.00716.60
7.4.300.0000.00616.48
7.4.290.0030.00316.40
7.4.280.0090.00016.63
7.4.270.0000.00716.56
7.4.260.0000.00513.21
7.4.250.0040.00416.32
7.4.240.0020.00516.53
7.4.230.0030.00316.32
7.4.220.0000.00716.35
7.4.210.0100.00716.58
7.4.200.0000.00716.35
7.4.150.0060.01316.40
7.4.140.0150.00716.37
7.4.130.0030.01416.33
7.4.120.0130.00716.45
7.4.110.0080.01216.16
7.4.100.0030.01416.42
7.4.90.0000.01816.30
7.4.80.0140.00616.55
7.4.70.0150.00316.50
7.4.60.0070.01316.56
7.4.50.0160.00316.25
7.4.40.0060.01216.52
7.4.30.0100.01316.42
7.4.20.0100.00716.54
7.4.10.0070.01116.48
7.4.00.0090.00916.49
7.3.330.0070.00016.32
7.3.320.0000.00513.33
7.3.310.0040.00416.47
7.3.300.0040.00416.24
7.3.290.0080.00816.37
7.3.270.0090.01216.46
7.3.260.0060.01616.24
7.3.250.0100.01116.36
7.3.240.0100.00716.35
7.3.230.0140.00316.37
7.3.220.0100.00716.38
7.3.210.0100.00716.58
7.3.200.0040.01516.58
7.3.190.0070.01016.38
7.3.180.0090.00916.43
7.3.170.0030.01316.27
7.3.160.0150.00616.48
7.3.150.0150.00616.45
7.3.140.0070.01016.30
7.3.130.0140.00316.29
7.3.120.0110.00816.57
7.3.110.0150.00616.68
7.3.100.0110.00616.38
7.3.90.0090.01216.26
7.3.80.0120.00616.30
7.3.70.0120.01216.40
7.3.60.0120.01216.39
7.3.50.0110.01116.31
7.3.40.0080.00916.37
7.3.30.0040.01416.40
7.3.20.0130.00716.48
7.3.10.0130.00616.47
7.3.00.0190.00716.39

preferences:
69.7 ms | 400 KiB | 5 Q