3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Model { protected $id; public function __construct($id = 0) { $this->id = $id; } public function __toString() { return print_r($this->generate(), true); } } class Bear extends Model { protected $relations = [ 'hasOne' => [ ['Fish', 'id', 'bear_id'] ] ]; public $data = [ ['id' => 1, 'name' => 'A'], ['id' => 2, 'name' => 'B'], ['id' => 3, 'name' => 'C'], ['id' => 4, 'name' => 'D'] ]; public function generate() { $relation = $this->relations['hasOne'][0]; $name = $relation[0]; $first = $relation[1]; $second = $relation[2]; $relation = (new $name)->data; $bear = $this->data[$this->id]; foreach ($relation as $key => $value) { if ($bear[$first] === $value[$second]) { $bear[$name][] = $value; } } return print_r($bear, true); } } class Fish extends Model { protected $relations = [ 'belongsTo' => [ ['Bear', 'bear_id', 'id'] ] ]; public $data = [ ['id' => 1, 'bear_id' => 1, 'name' => 'fish_a'], ['id' => 2, 'bear_id' => 2, 'name' => 'fish_b'], ['id' => 3, 'bear_id' => 3, 'name' => 'fish_c'], ['id' => 4, 'bear_id' => 1, 'name' => 'fish_d'] ]; public function generate() { $relation = $this->relations['belongsTo'][0]; $name = $relation[0]; $first = $relation[1]; $second = $relation[2]; $relation = (new $name)->data; $fish = $this->data[$this->id]; foreach ($relation as $key => $value) { if ($fish[$first] === $value[$second]) { $fish[$first] = $value; } } return print_r($fish, true); } } $bear = new Bear(0); $fish = new Fish(0); echo ' <meta charset="utf-8"> <pre> Database `bears` Database `fishes` ┌────────────┬──────────────┐ ┌────────────┬──────────────┬──────────────┐ │ id │ name │ │ id │ bear_id │ name │ ├────────────┼──────────────┤ ├────────────┼──────────────┼──────────────┤ │ 1 │ A │ │ 1 │ 1 │ fish_a │ ├────────────┼──────────────┤ ├────────────┼──────────────┼──────────────┤ │ 2 │ B │ │ 2 │ 2 │ fish_b │ ├────────────┼──────────────┤ ├────────────┼──────────────┼──────────────┤ │ 3 │ C │ │ 3 │ 3 │ fish_c │ ├────────────┼──────────────┤ ├────────────┼──────────────┼──────────────┤ │ 4 │ D │ │ 4 │ 1 │ fish_d │ └────────────┴──────────────┘ └────────────┴──────────────┴──────────────┘ ', $bear, '<hr>', $fish;

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.70.0060.01318.18
8.3.60.0100.01316.88
8.3.50.0100.00922.84
8.3.40.0120.00318.78
8.3.30.0110.00419.21
8.3.20.0040.00420.30
8.3.10.0030.00523.54
8.3.00.0040.00417.75
8.2.180.0160.00716.63
8.2.170.0110.00422.96
8.2.160.0100.00320.36
8.2.150.0000.00824.18
8.2.140.0060.00324.66
8.2.130.0070.00026.16
8.2.120.0000.00821.10
8.2.110.0040.00719.33
8.2.100.0110.00317.91
8.2.90.0030.00519.16
8.2.80.0050.00317.97
8.2.70.0030.00517.63
8.2.60.0000.00817.93
8.2.50.0000.00818.10
8.2.40.0030.00518.09
8.2.30.0040.00418.06
8.2.20.0040.00417.76
8.2.10.0000.00718.10
8.2.00.0030.00617.83
8.1.280.0130.00325.92
8.1.270.0000.00823.91
8.1.260.0030.00526.35
8.1.250.0040.00428.09
8.1.240.0070.00422.37
8.1.230.0080.00417.70
8.1.220.0030.00617.74
8.1.210.0040.00418.77
8.1.200.0000.01017.35
8.1.190.0000.00817.23
8.1.180.0060.00318.10
8.1.170.0000.00818.59
8.1.160.0000.00722.05
8.1.150.0040.00418.96
8.1.140.0080.00017.35
8.1.130.0030.00317.83
8.1.120.0040.00417.51
8.1.110.0030.00517.47
8.1.100.0040.00417.42
8.1.90.0050.00217.39
8.1.80.0060.00317.47
8.1.70.0070.00017.45
8.1.60.0030.00517.62
8.1.50.0040.00417.56
8.1.40.0040.00417.43
8.1.30.0040.00417.71
8.1.20.0080.00017.72
8.1.10.0040.00417.56
8.1.00.0040.00417.55
8.0.300.0000.00718.77
8.0.290.0070.00016.75
8.0.280.0030.00518.52
8.0.270.0000.00716.84
8.0.260.0030.00317.34
8.0.250.0030.00317.02
8.0.240.0040.00416.96
8.0.230.0030.00416.85
8.0.220.0000.00716.89
8.0.210.0050.00216.88
8.0.200.0040.00416.98
8.0.190.0000.00817.02
8.0.180.0050.00316.93
8.0.170.0000.00816.83
8.0.160.0040.00416.98
8.0.150.0000.00816.71
8.0.140.0040.00416.92
8.0.130.0030.00313.39
8.0.120.0040.00416.88
8.0.110.0040.00416.88
8.0.100.0000.00716.89
8.0.90.0050.00216.82
8.0.80.0060.01016.84
8.0.70.0040.00416.87
8.0.60.0040.00416.80
8.0.50.0040.00416.92
8.0.30.0130.00817.05
8.0.20.0120.00917.40
8.0.10.0050.00217.14
8.0.00.0130.00516.64
7.4.330.0000.00615.00
7.4.320.0030.00316.64
7.4.300.0040.00416.54
7.4.290.0050.00316.50
7.4.280.0000.00816.63
7.4.270.0080.00016.64
7.4.260.0030.00616.55
7.4.250.0080.00016.59
7.4.240.0050.00216.57
7.4.230.0000.00716.70
7.4.220.0090.00916.56
7.4.210.0060.00916.63
7.4.200.0000.00716.60
7.4.160.0080.00816.55
7.4.150.0100.00917.40
7.4.140.0150.00517.86
7.4.130.0070.01316.65
7.4.120.0110.01116.54
7.4.110.0070.01116.43
7.4.100.0190.00016.71
7.4.90.0090.01016.65
7.4.80.0070.01419.39
7.4.70.0100.01016.70
7.4.60.0030.01316.45
7.4.50.0020.00216.34
7.4.40.0090.00816.55
7.4.30.0060.01316.52
7.4.10.0060.01315.83
7.4.00.0070.00715.56
7.3.330.0050.00513.41
7.3.320.0030.00313.20
7.3.310.0040.00416.30
7.3.300.0000.00716.36
7.3.290.0030.01016.48
7.3.280.0120.00516.39
7.3.270.0040.01517.40
7.3.260.0110.00716.53
7.3.240.0080.01116.46
7.3.230.0130.00316.39
7.3.210.0060.01716.43
7.3.200.0160.00619.39
7.3.190.0110.00616.48
7.3.180.0060.00916.45
7.3.170.0160.00316.39
7.3.160.0080.00816.46
7.3.130.0070.00915.56
7.3.120.0090.01115.75
7.3.110.0100.00515.55
7.3.100.0050.01015.53
7.3.90.0060.01115.70
7.3.80.0060.00615.56
7.3.70.0030.01315.47
7.3.60.0080.00315.66
7.3.50.0020.01115.55
7.3.40.0000.01015.65
7.3.30.0070.00915.54
7.3.20.0060.01217.36
7.3.10.0050.01017.45
7.3.00.0030.01017.46
7.2.330.0080.00816.72
7.2.320.0070.01116.46
7.2.310.0120.00616.52
7.2.300.0120.00616.77
7.2.290.0090.01316.82
7.2.260.0050.01415.91
7.2.250.0060.01115.88
7.2.240.0070.00815.83
7.2.230.0060.00815.75
7.2.220.0030.01215.95
7.2.210.0080.00815.75
7.2.200.0040.01215.84
7.2.190.0050.01015.90
7.2.180.0070.00315.88
7.2.170.0070.00815.79
7.2.160.0040.01215.80
7.2.150.0050.00917.64
7.2.140.0020.01317.70
7.2.130.0070.00917.61
7.2.120.0060.01117.68
7.2.110.0080.00617.72
7.2.100.0070.00417.71
7.2.90.0120.00417.76
7.2.80.0060.00717.78
7.2.70.0060.01017.65
7.2.60.0080.01017.53
7.2.50.0110.00517.78
7.2.40.0090.00717.78
7.2.30.0080.00617.78
7.2.20.0060.00817.67
7.2.10.0070.00717.78
7.2.00.0040.00918.13
7.1.330.0070.01016.75
7.1.320.0040.01216.70
7.1.310.0040.01016.54
7.1.300.0060.00616.57
7.1.290.0020.01116.49
7.1.280.0080.00416.49
7.1.270.0060.00616.63
7.1.260.0070.00716.67
7.1.250.0050.01016.59
7.1.240.0030.01016.69
7.1.230.0030.00916.66
7.1.220.0080.00916.47
7.1.210.0070.00916.51
7.1.200.0020.01016.24
7.1.190.0040.00716.45
7.1.180.0150.00216.52
7.1.170.0110.00716.63
7.1.160.0050.00916.54
7.1.150.0050.00816.73
7.1.140.0100.00216.61
7.1.130.0050.00716.51
7.1.120.0070.00416.52
7.1.110.0070.00516.56
7.1.100.0060.00917.07
7.1.90.0020.01016.74
7.1.80.0000.01116.63
7.1.70.0050.00816.87
7.1.60.0060.00917.53
7.1.50.0010.01216.61
7.1.40.0070.00416.62
7.1.30.0020.01416.44
7.1.20.0080.00316.42
7.1.10.0060.00716.71
7.1.00.0040.03318.49
7.0.330.0050.00816.12
7.0.320.0070.00916.25
7.0.310.0080.00616.29
7.0.300.0070.00716.15
7.0.290.0050.01216.18
7.0.280.0060.00616.03
7.0.270.0050.01016.13
7.0.260.0060.00716.19
7.0.250.0080.00516.19
7.0.240.0040.00916.34
7.0.230.0070.00716.19
7.0.220.0050.00915.96
7.0.210.0070.00716.21
7.0.200.0010.00916.35
7.0.190.0060.00516.13
7.0.180.0040.01116.16
7.0.170.0050.00716.24
7.0.160.0080.00716.09
7.0.150.0060.00516.29
7.0.140.0060.03018.14
7.0.130.0070.00916.17
7.0.120.0040.00916.16
7.0.110.0100.00716.17
7.0.100.0060.03417.54
7.0.90.0080.03017.53
7.0.80.0030.03217.59
7.0.70.0060.03217.52
7.0.60.0070.02817.44
7.0.50.0100.02917.52
7.0.40.0080.03416.14
7.0.30.0110.02616.10
7.0.20.0030.02216.20
7.0.10.0040.03616.26
7.0.00.0030.03616.14
5.6.400.0070.00715.43
5.6.390.0060.01015.47
5.6.380.0050.01015.38
5.6.370.0090.00515.31
5.6.360.0120.00515.14
5.6.350.0090.00715.35
5.6.340.0060.00815.25
5.6.330.0100.00615.21
5.6.320.0050.00915.51
5.6.310.0050.00915.20
5.6.300.0070.00715.25
5.6.290.0050.00515.38
5.6.280.0130.02217.19
5.6.270.0070.00915.29
5.6.260.0050.00815.27
5.6.250.0060.03017.10
5.6.240.0070.02417.14
5.6.230.0080.03017.19
5.6.220.0030.02117.06
5.6.210.0070.02917.08
5.6.200.0100.03017.15
5.6.190.0150.01417.33
5.6.180.0070.03417.17
5.6.170.0050.03217.26
5.6.160.0060.03317.24
5.6.150.0070.03117.22
5.6.140.0060.03017.22
5.6.130.0060.03217.27
5.6.120.0110.02817.22
5.6.110.0040.02617.22
5.6.100.0040.02117.16
5.6.90.0060.03317.17
5.6.80.0060.01816.97
5.6.70.0040.02016.96
5.6.60.0040.02016.90
5.6.50.0050.01916.89
5.6.40.0100.01717.08
5.6.30.0020.02316.97
5.6.20.0060.02616.80
5.6.10.0020.02716.83
5.6.00.0070.02016.96
5.5.380.0040.03217.03
5.5.370.0050.03117.09
5.5.360.0070.03217.09
5.5.350.0070.02717.11
5.5.340.0070.02217.20
5.5.330.0060.03117.15
5.5.320.0030.03517.32
5.5.310.0110.02817.11
5.5.300.0080.03017.20
5.5.290.0080.03117.08
5.5.280.0050.03717.09
5.5.270.0070.02917.20
5.5.260.0080.02117.19
5.5.250.0100.02717.19
5.5.240.0100.01416.86
5.5.230.0130.01316.82
5.5.220.0100.01416.97
5.5.210.0090.01516.84
5.5.200.0080.02716.89
5.5.190.0070.01816.95
5.5.180.0090.01416.88
5.5.170.0060.00815.27
5.5.160.0060.01916.88
5.5.150.0070.02516.89
5.5.140.0060.02616.90
5.5.130.0060.01716.86
5.5.120.0070.01716.76
5.5.110.0080.02116.94
5.5.100.0030.01916.76
5.5.90.0020.02116.89
5.5.80.0040.01916.90
5.5.70.0070.01616.79
5.5.60.0100.02516.89
5.5.50.0040.02016.84
5.5.40.0080.01616.81
5.5.30.0050.01816.71
5.5.20.0080.01516.89
5.5.10.0070.01716.67
5.5.00.0020.02016.70
5.4.450.0060.03014.38
5.4.440.0030.03414.51
5.4.430.0120.02714.47
5.4.420.0080.03214.63
5.4.410.0010.02114.50
5.4.400.0050.01514.24
5.4.390.0030.02614.25
5.4.380.0070.01614.39
5.4.370.0040.01814.33
5.4.360.0040.01814.20
5.4.350.0070.01614.46
5.4.340.0050.02214.30
5.4.330.0000.00812.04
5.4.320.0080.02614.31
5.4.310.0040.01614.36
5.4.300.0040.01814.28
5.4.290.0060.02314.31
5.4.280.0050.02014.39
5.4.270.0060.01914.30
5.4.260.0090.02014.40
5.4.250.0020.01814.29
5.4.240.0020.01714.36
5.4.230.0050.02414.29
5.4.220.0030.03314.28
5.4.210.0070.01514.28
5.4.200.0020.01914.32
5.4.190.0030.01814.27
5.4.180.0080.01514.24
5.4.170.0050.01814.41
5.4.160.0010.02114.37
5.4.150.0050.01614.21
5.4.140.0060.01513.41
5.4.130.0030.01613.48
5.4.120.0070.01313.43
5.4.110.0040.01813.44
5.4.100.0050.01813.48
5.4.90.0050.01813.55
5.4.80.0100.01413.51
5.4.70.0050.02313.50
5.4.60.0050.02813.52
5.4.50.0050.02913.45
5.4.40.0070.02913.46
5.4.30.0130.02313.60
5.4.20.0080.02513.59
5.4.10.0080.02713.62
5.4.00.0020.03013.34
5.3.290.0070.03714.81
5.3.280.0070.03314.66
5.3.270.0000.04014.63
5.3.260.0070.03314.63
5.3.250.0030.04014.56
5.3.240.0030.03714.56
5.3.230.0030.03714.66
5.3.220.0030.04014.55
5.3.210.0100.07714.50
5.3.200.0070.03314.71
5.3.190.0100.03314.66
5.3.180.0070.08014.63
5.3.170.0100.06714.55
5.3.160.0030.06714.69
5.3.150.0030.05714.58
5.3.140.0130.07314.68
5.3.130.0030.08014.59
5.3.120.0100.07714.53
5.3.110.0070.07014.61
5.3.100.0100.07014.16
5.3.90.0100.06713.96
5.3.80.0030.08014.08
5.3.70.0130.07014.01
5.3.60.0130.07014.13
5.3.50.0070.07714.06
5.3.40.0070.07014.04
5.3.30.0070.07013.93
5.3.20.0030.07713.76
5.3.10.0100.04013.59
5.3.00.0070.07013.57
5.2.170.0030.06311.22
5.2.160.0030.06311.02
5.2.150.0070.06311.21
5.2.140.0000.06711.06
5.2.130.0070.05711.22
5.2.120.0030.05711.00
5.2.110.0070.06011.17
5.2.100.0030.06711.16
5.2.90.0100.04311.25
5.2.80.0130.05711.14
5.2.70.0130.05711.20
5.2.60.0030.04711.11
5.2.50.0100.04010.94
5.2.40.0100.05710.93
5.2.30.0100.05311.02
5.2.20.0070.05710.93
5.2.10.0070.05710.88
5.2.00.0030.06010.64
5.1.60.0070.03310.07
5.1.50.0070.05310.13
5.1.40.0030.05710.07
5.1.30.0030.05710.26
5.1.20.0070.05310.44
5.1.10.0070.05310.14
5.1.00.0030.03310.07
5.0.50.0000.04010.07
5.0.40.0000.02710.07
5.0.30.0000.05310.07
5.0.20.0030.03310.07
5.0.10.0100.01710.07
5.0.00.0030.06010.07
4.4.90.0000.03710.07
4.4.80.0030.03310.07
4.4.70.0000.02010.07
4.4.60.0000.04010.07
4.4.50.0000.03710.07
4.4.40.0070.04310.07
4.4.30.0030.03710.07
4.4.20.0000.03310.07
4.4.10.0030.03710.07
4.4.00.0030.05310.07
4.3.110.0030.03710.07
4.3.100.0000.03010.07
4.3.90.0030.03310.07
4.3.80.0000.03710.07
4.3.70.0030.03710.07
4.3.60.0000.03710.07
4.3.50.0030.03010.07
4.3.40.0000.05710.07
4.3.30.0030.01710.07
4.3.20.0000.02310.07
4.3.10.0030.02310.07
4.3.00.0000.03710.07

preferences:
42.61 ms | 401 KiB | 5 Q