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 ' 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: ', $bear, ' Fish:', $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.0140.00316.58
8.3.60.0220.00416.47
8.3.50.0090.00722.93
8.3.40.0090.00618.61
8.3.30.0090.00619.17
8.3.20.0040.00420.15
8.3.10.0000.00823.36
8.3.00.0000.00817.75
8.2.180.0160.00816.37
8.2.170.0040.01122.96
8.2.160.0040.01120.39
8.2.150.0040.00424.18
8.2.140.0000.00824.66
8.2.130.0000.00726.16
8.2.120.0090.00021.16
8.2.110.0040.00419.25
8.2.100.0100.00417.78
8.2.90.0030.00517.38
8.2.80.0030.00617.97
8.2.70.0080.00018.05
8.2.60.0030.00618.05
8.2.50.0050.00318.10
8.2.40.0030.00622.23
8.2.30.0080.00018.19
8.2.20.0030.00517.88
8.2.10.0030.00618.20
8.2.00.0020.00517.90
8.1.280.0160.00325.92
8.1.270.0050.00323.96
8.1.260.0040.00426.35
8.1.250.0000.00728.09
8.1.240.0060.00322.08
8.1.230.0040.00822.66
8.1.220.0030.00517.74
8.1.210.0050.00318.77
8.1.200.0090.00317.36
8.1.190.0100.00017.23
8.1.180.0000.00818.10
8.1.170.0050.00318.61
8.1.160.0040.00421.99
8.1.150.0070.00018.86
8.1.140.0040.00417.38
8.1.130.0030.00317.85
8.1.120.0040.00417.48
8.1.110.0050.00317.48
8.1.100.0040.00417.51
8.1.90.0000.00717.44
8.1.80.0040.00417.38
8.1.70.0030.00317.44
8.1.60.0040.00417.61
8.1.50.0000.00817.55
8.1.40.0040.00417.51
8.1.30.0040.00417.60
8.1.20.0040.00417.61
8.1.10.0080.00017.59
8.1.00.0080.00017.52
8.0.300.0000.00719.98
8.0.290.0070.00316.75
8.0.280.0000.00718.48
8.0.270.0000.00717.30
8.0.260.0000.00617.19
8.0.250.0030.00316.99
8.0.240.0030.00616.98
8.0.230.0070.00016.86
8.0.220.0030.00516.91
8.0.210.0000.00716.80
8.0.200.0000.00716.86
8.0.190.0060.00316.86
8.0.180.0000.00716.79
8.0.170.0000.00816.83
8.0.160.0000.00816.96
8.0.150.0040.00416.86
8.0.140.0040.00416.76
8.0.130.0060.00313.31
8.0.120.0070.00016.86
8.0.110.0040.00416.93
8.0.100.0040.00416.93
8.0.90.0030.00316.93
8.0.80.0110.01116.91
8.0.70.0000.00716.75
8.0.60.0070.00016.81
8.0.50.0040.00416.98
8.0.30.0080.01416.98
8.0.20.0070.01217.40
8.0.10.0040.00416.87
8.0.00.0040.01316.77
7.4.330.0050.00015.15
7.4.320.0000.00616.46
7.4.300.0030.00716.62
7.4.290.0050.00316.52
7.4.280.0030.00516.52
7.4.270.0000.00716.67
7.4.260.0030.00316.53
7.4.250.0040.00416.39
7.4.240.0030.00516.54
7.4.230.0060.00316.64
7.4.220.0040.01916.57
7.4.210.0060.00916.60
7.4.200.0070.00016.36
7.4.160.0130.00316.41
7.4.150.0130.00617.40
7.4.140.0090.01117.86
7.4.130.0100.00916.60
7.4.120.0130.01116.63
7.4.110.0070.01016.36
7.4.100.0100.01016.45
7.4.90.0130.00316.39
7.4.80.0080.00819.39
7.4.70.0210.00016.46
7.4.60.0100.00716.45
7.4.50.0030.00316.15
7.4.40.0110.00716.59
7.4.30.0080.00816.49
7.4.00.0000.01315.23
7.3.330.0050.00513.18
7.3.320.0050.00013.34
7.3.310.0070.00016.25
7.3.300.0040.00416.35
7.3.290.0110.00316.40
7.3.280.0110.00816.39
7.3.270.0160.00317.40
7.3.260.0140.00316.56
7.3.250.0100.01216.65
7.3.240.0040.01216.50
7.3.230.0100.00716.39
7.3.210.0100.00716.48
7.3.200.0090.00919.39
7.3.190.0100.00716.38
7.3.180.0060.00916.41
7.3.170.0000.01516.34
7.3.160.0120.00416.45
7.3.00.0170.00016.25
7.2.330.0090.00916.77
7.2.320.0030.01516.43
7.2.310.0120.00416.80
7.2.300.0060.00916.68
7.2.290.0100.01016.52
7.2.130.0090.00916.57
7.2.120.0110.00716.42
7.2.110.0070.01016.82
7.2.100.0090.01216.84
7.2.90.0000.01417.03
7.2.80.0120.00616.73
7.2.70.0100.01016.68
7.2.60.0070.01017.07
7.2.50.0110.00416.77
7.2.40.0150.00016.60
7.2.30.0030.01016.48
7.2.20.0100.01016.60
7.2.10.0100.00716.89
7.2.00.0060.00718.21
7.1.250.0090.00915.66
7.1.240.0110.00615.78
7.1.230.0150.00415.90
7.1.220.0130.00315.76
7.1.210.0060.01215.63
7.1.200.0140.00615.86
7.1.190.0090.00615.68
7.1.180.0150.00015.63
7.1.170.0140.00015.66
7.1.160.0070.00415.73
7.1.150.0090.00915.71
7.1.140.0060.01015.76
7.1.130.0140.00015.48
7.1.120.0080.00415.85
7.1.110.0120.00315.89
7.1.100.0050.00816.84
7.1.90.0120.00315.92
7.1.80.0110.00015.84
7.1.70.0090.00316.46
7.1.60.0050.01417.61
7.1.50.0090.00816.35
7.1.40.0170.00415.69
7.1.30.0110.00715.39
7.1.20.0090.00615.78
7.1.10.0130.00015.68
7.1.00.0060.04318.95
7.0.330.0140.00315.01
7.0.320.0070.00715.26
7.0.310.0170.00315.47
7.0.300.0060.00915.40
7.0.290.0100.00715.29
7.0.280.0100.01015.42
7.0.270.0140.00015.32
7.0.260.0080.00615.47
7.0.250.0130.00415.36
7.0.240.0070.00715.39
7.0.230.0060.00615.43
7.0.220.0120.00615.10
7.0.210.0110.00415.09
7.0.200.0060.00715.98
7.0.190.0110.01114.82
7.0.180.0110.00414.81
7.0.170.0060.00914.90
7.0.160.0100.01015.34
7.0.150.0060.00915.31
7.0.140.0020.04418.58
7.0.130.0030.01015.43
7.0.120.0090.00614.96
7.0.110.0090.01015.06
7.0.100.0090.00615.24
7.0.90.0150.00315.27
7.0.80.0070.01115.25
7.0.70.0080.00915.36
7.0.60.0050.02717.50
7.0.50.0100.02216.70
7.0.40.0090.04516.69
7.0.30.0200.04316.74
7.0.20.0170.02016.69
7.0.10.0080.04516.57
7.0.00.0090.03016.77
5.6.380.0070.00314.75
5.6.370.0060.01014.31
5.6.360.0070.00314.46
5.6.350.0110.00414.30
5.6.340.0100.00514.51
5.6.330.0070.00314.11
5.6.320.0060.00614.41
5.6.310.0040.00414.39
5.6.300.0070.00414.38
5.6.290.0080.00814.20
5.6.280.0100.03717.76
5.6.270.0040.01214.29
5.6.260.0040.01214.35
5.6.250.0070.01014.37
5.6.240.0070.00314.43
5.6.230.0000.01014.44
5.6.220.0060.00614.34
5.6.210.0080.03917.53
5.6.200.0110.04316.12
5.6.190.0050.03717.40
5.6.180.2030.02617.33
5.6.170.0150.03317.43
5.6.160.0100.02517.48
5.6.150.0080.04116.41
5.6.140.0100.04016.37
5.6.130.0100.02016.21
5.6.120.0020.04517.80
5.6.110.0050.02517.70
5.6.100.0090.04717.69
5.6.90.0160.03317.68
5.6.80.0070.03517.45
5.6.70.0250.03217.45
5.6.60.0090.00314.41
5.6.50.0070.00714.20
5.6.40.0000.01614.18
5.6.30.0070.01014.16
5.6.20.0040.01414.07
5.6.10.0090.00614.27
5.6.00.0120.00014.33
5.5.380.0040.00811.31
5.5.370.0080.00011.26
5.5.360.0090.00011.29
5.5.350.0070.04615.78
5.5.340.0090.03914.58
5.5.330.0090.04315.97
5.5.320.0210.02515.89
5.5.310.0160.04015.94
5.5.300.0050.03614.59
5.5.290.0110.02014.59
5.5.280.0080.02315.96
5.5.270.0070.04516.03
5.5.260.0080.04416.02
5.5.250.0070.02816.00
5.5.240.0050.03015.67
5.5.230.0000.01511.27
5.5.220.0040.00811.05
5.5.210.0000.00910.90
5.5.200.0080.00310.98
5.5.190.0030.00811.14
5.5.180.0030.01011.44
5.5.170.0080.00311.32
5.5.160.0030.00711.28
5.5.150.0030.01011.32
5.5.140.0090.00311.33
5.5.130.0080.00611.09
5.5.120.0030.01011.04
5.5.110.0040.00711.18
5.5.100.0060.00611.30
5.5.90.0060.00911.39
5.5.80.0030.00811.20
5.5.70.0030.01011.27
5.5.60.0000.01311.25
5.5.50.0030.00611.27
5.5.40.0070.00711.16
5.5.30.0030.01011.41
5.5.20.0040.00711.09
5.5.10.0030.00911.12
5.5.00.0030.01011.09
5.4.450.0340.03115.43
5.4.440.0120.03015.22
5.4.430.0250.02715.40
5.4.420.0120.02815.28
5.4.410.0300.03015.26
5.4.400.0350.03015.20
5.4.390.0300.03215.11
5.4.380.0050.03114.92
5.4.370.0020.02515.01
5.4.360.0090.02514.83
5.4.350.0050.02711.50
5.4.340.0030.02211.54
5.4.330.0000.00710.90
5.4.320.0060.01911.82
5.4.310.0050.02211.89
5.4.300.0100.02511.81
5.4.290.0040.02611.71
5.4.280.0040.02311.71
5.4.270.0060.02211.74
5.4.260.0050.02411.75
5.4.250.0060.02311.79
5.4.240.0080.02111.79
5.4.230.0070.02211.77
5.4.220.0090.01811.66
5.4.210.0050.02311.77
5.4.200.0020.02611.78
5.4.190.0080.02411.77
5.4.180.0070.02211.66
5.4.170.0100.02411.78
5.4.160.0050.02111.66
5.4.150.0090.01911.84
5.4.140.0090.02511.61
5.4.130.0100.02311.63
5.4.120.0080.02811.68
5.4.110.0060.03111.52
5.4.100.0060.02111.69
5.4.90.0060.02211.66
5.4.80.0060.02111.66
5.4.70.0060.02311.65
5.4.60.0100.02411.68
5.4.50.0070.02411.68
5.4.40.0060.02011.62
5.4.30.0100.02111.64
5.4.20.0050.02111.59
5.4.10.0060.02311.61
5.4.00.0030.02411.28
5.3.290.0060.02311.85
5.3.280.0070.02011.80
5.3.270.0060.02311.81
5.3.260.0090.02311.81
5.3.250.0090.02011.81
5.3.240.0100.01911.81
5.3.230.0030.02411.80
5.3.220.0080.02411.79
5.3.210.0070.02711.79
5.3.200.0080.02111.79
5.3.190.0050.02211.79
5.3.180.0050.02211.79
5.3.170.0070.02011.78
5.3.160.0080.02011.79
5.3.150.0080.02111.79
5.3.140.0060.02111.78
5.3.130.0030.02511.78
5.3.120.0050.02211.78
5.3.110.0070.02111.78
5.3.100.0040.02211.51
5.3.90.0050.02211.50
5.3.80.0060.02411.50
5.3.70.0050.02111.50
5.3.60.0050.02111.49
5.3.50.0050.02111.46
5.3.40.0040.02311.46
5.3.30.0030.02211.45
5.3.20.0060.01911.33
5.3.10.0050.02011.32
5.3.00.0020.02311.31
5.2.170.0040.01810.06
5.2.160.0060.01610.06
5.2.150.0060.02310.06
5.2.140.0030.01910.06
5.2.130.0040.01610.04
5.2.120.0040.01710.04
5.2.110.0060.01610.05
5.2.100.0040.01810.04
5.2.90.0050.01610.04
5.2.80.0050.01910.04
5.2.70.0020.02010.04
5.2.60.0040.02110.02
5.2.50.0040.02510.00
5.2.40.0080.0189.99
5.2.30.0030.0199.98
5.2.20.0050.0179.97
5.2.10.0030.0199.93
5.2.00.0080.0149.86
5.1.60.0020.0159.50
5.1.50.0020.0209.50
5.1.40.0030.0209.49
5.1.30.0050.0159.66
5.1.20.0020.0199.67
5.1.10.0060.0149.53
5.1.00.0030.0169.54
5.0.50.0050.0118.77
5.0.40.0040.0118.71
5.0.30.0030.0168.61
5.0.20.0020.0128.59
5.0.10.0010.0138.58
5.0.00.0020.0178.58
4.4.90.0040.0087.84
4.4.80.0020.0137.83
4.4.70.0030.0117.83
4.4.60.0020.0117.83
4.4.50.0060.0077.83
4.4.40.0020.0147.80
4.4.30.0010.0117.83
4.4.20.0050.0087.87
4.4.10.0040.0097.88
4.4.00.0050.0157.83
4.3.110.0040.0097.79
4.3.100.0040.0087.78
4.3.90.0040.0077.77
4.3.80.0020.0167.74
4.3.70.0040.0077.77
4.3.60.0010.0107.76
4.3.50.0040.0097.76
4.3.40.0020.0157.72
4.3.30.0020.0107.10
4.3.20.0010.0137.09
4.3.10.0030.0107.07
4.3.00.0090.0089.36

preferences:
36.8 ms | 401 KiB | 5 Q