3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array ( // Sub-array 1 array ( // Story 'Monkey 1' - Has identical sub-sub-arrays 'Monkey 2' and 'Monkey 3' and will be merged with them. array ( "header" => "This is a story about a monkey.", 'keywords' => array( "Trees", "Monkey", "Flying", "Drink", "Vacation", "Coconut", "Big", "Bonobo", "Climbing") ), // Story 'Cat 1' - Has identical sub-sub-array 'Cat 2' and will be merged with it. array ( "header" => "Here's a catarific story about a cat", 'keywords' => array( "meauw", "raaaw", "kitty", "growup", "Fun", "claws", "fish", "salmon") ) ), // Sub-array 2 array ( // Story 'Monkey 2' - Has identical sub-sub-arrays 'Monkey 1' and 'Monkey 3' and will be merged with them. array ( "header" => "This is another, but different story, about a monkey.", 'keywords' => array( "Monkey", "Big", "Trees", "Bonobo", "Fun", "Dance", "Cow", "Coconuts") ), // Story 'Cat 2' - Has identical sub-sub-array 'Cat 1' and will be merged with it. array ( "header" => "Here's a different story about a cat", 'keywords' => array( "meauwe", "ball", "cat", "kitten", "claws", "sleep", "fish", "purr") ) ), // Sub-array 3 array ( // Story 'Monkey 3' - Has identical sub-sub-arrays 'Monkey 1' and 'Monkey 2' and will be merged with them. array ( "header" => "This is a third story about a monkey.", 'keywords' => array( "Jungle", "tree", "monkey", "Bonobo", "Fun", "Dance", "climbing", "Coconut", "pretty") ), // Story 'Fireman 1' - Has no identical sub-sub-arrays and will not be merged. array ( "header" => "This is a story about a fireman", 'keywords' => array( "fire", "explosion", "burning", "rescue", "happy", "help", "water", "car") ) ) ); //flatten array to make it simpler $new =[]; foreach($array as $subarr){ $new = array_merge($new, $subarr); } $threshold = 3; $threshold_word = $threshold; $lev_point_value = 0; $merged=[]; foreach($new as $key => $story){ // create regex pattern to find similar items $words = "/" . implode("|", $story["keywords"]) . "/i"; foreach($new as $key2 => $story2){ // only loop new items and items that has not been merged already if($key != $key2 && $key2 > $key && !in_array($key2, $merged)){ foreach ($story['keywords'] as $item1){ foreach ($story2["keywords"] as $item2){ if (levenshtein($item1, $item2) <= $lev_point_value) { $threshold_word++; // If the count of words from preg_grep is above threshold it's mergable if(count(preg_grep($words, $story2["keywords"])) > $threshold){ // debug //echo $key . " " . $key2 . "\n"; //echo $story["header"] . " = " . $story2["header"] ."\n\n"; // if the item does not exist create it first to remove notices if(!isset($res[$key])) $res[$key] = ["header" => [], "keywords" =>[]]; // add headers $res[$key]["header"][] = $story["header"]; $res[$key]["header"][] = $story2["header"]; // only keep unique $res[$key]["header"] = array_unique($res[$key]["header"]); // add keywords and remove duplicates $res[$key]["keywords"] = array_merge($res[$key]["keywords"], $story["keywords"], $story2["keywords"]); $res[$key]["keywords"] = array_unique($res[$key]["keywords"]); // add key2 to merged so that we don't merge this again. $merged[] = $key2; } } } } } } } var_dump($res);

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.41
8.3.50.0070.00716.52
8.3.40.0080.00818.92
8.3.30.0180.00419.10
8.3.20.0030.00519.10
8.3.10.0000.00821.04
8.3.00.0080.00018.04
8.2.180.0090.00618.41
8.2.170.0080.00822.96
8.2.160.0110.00719.09
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0060.00320.14
8.2.120.0080.00026.35
8.2.110.0090.00020.24
8.2.100.0040.00818.03
8.2.90.0000.00817.88
8.2.80.0040.00419.03
8.2.70.0030.00617.93
8.2.60.0080.00018.05
8.2.50.0080.00018.10
8.2.40.0000.00821.27
8.2.30.0000.00719.56
8.2.20.0030.00518.31
8.2.10.0040.00418.26
8.2.00.0000.00719.49
8.1.280.0160.00625.92
8.1.270.0050.00323.91
8.1.260.0030.00626.35
8.1.250.0080.00028.09
8.1.240.0030.00617.55
8.1.230.0040.00720.44
8.1.220.0080.00017.91
8.1.210.0060.00618.77
8.1.200.0080.00017.50
8.1.190.0030.00617.60
8.1.180.0080.00418.10
8.1.170.0050.00318.84
8.1.160.0050.00320.75
8.1.150.0040.00418.93
8.1.140.0000.00817.78
8.1.130.0000.00719.09
8.1.120.0100.00017.55
8.1.110.0000.00817.65
8.1.100.0000.00817.54
8.1.90.0050.00317.68
8.1.80.0050.00317.59
8.1.70.0030.00517.54
8.1.60.0000.01017.77
8.1.50.0030.00517.60
8.1.40.0060.00617.72
8.1.30.0000.00817.81
8.1.20.0000.00817.76
8.1.10.0090.00017.75
8.1.00.0000.00917.58
8.0.300.0000.00718.77
8.0.290.0040.00417.00
8.0.280.0000.00718.54
8.0.270.0000.00817.32
8.0.260.0000.00717.41
8.0.250.0030.00517.05
8.0.240.0000.00717.21
8.0.230.0030.00617.07
8.0.220.0030.00316.96
8.0.210.0000.00716.99
8.0.200.0030.00317.02
8.0.190.0020.00517.17
8.0.180.0030.00616.98
8.0.170.0030.00617.16
8.0.160.0060.00317.17
8.0.150.0070.00016.98
8.0.140.0000.00716.98
8.0.130.0070.00013.52
8.0.120.0040.00416.99
8.0.110.0050.00517.04
8.0.100.0040.00417.04
8.0.90.0000.00817.09
8.0.80.0110.01117.05
8.0.70.0040.00417.20
8.0.60.0030.00517.13
8.0.50.0040.00417.13
8.0.30.0100.01017.26
8.0.20.0080.01117.40
8.0.10.0040.00417.17
8.0.00.0110.00916.92
7.4.330.0000.00515.55
7.4.320.0000.00716.77
7.4.300.0050.00216.86
7.4.290.0070.00016.93
7.4.280.0000.00816.88
7.4.270.0070.00016.88
7.4.260.0000.00816.82
7.4.250.0000.00816.75
7.4.240.0070.00016.78
7.4.230.0070.00016.85
7.4.220.0030.00616.85
7.4.210.0060.01116.89
7.4.200.0040.00416.52
7.4.160.0070.01316.73
7.4.140.0090.01217.86
7.4.130.0190.00016.67
7.4.120.0090.01116.73
7.4.110.0130.01016.51
7.4.100.0160.00616.70
7.4.90.0090.01516.68
7.4.80.0120.00719.39
7.4.70.0100.00716.90
7.4.60.0060.01217.07
7.4.50.0100.01016.80
7.4.40.0190.00416.89
7.4.00.0090.01015.12
7.3.330.0030.00513.26
7.3.320.0030.00313.44
7.3.310.0000.00716.52
7.3.300.0040.00416.58
7.3.290.0000.00716.43
7.3.280.0080.01016.48
7.3.260.0110.00816.60
7.3.240.0100.01216.70
7.3.230.0090.00916.89
7.3.210.0060.01516.80
7.3.200.0150.00316.76
7.3.190.0100.00716.73
7.3.180.0030.01416.52
7.3.170.0070.01316.55
7.3.160.0060.01216.83
7.3.120.0080.01015.14
7.3.110.0070.01114.93
7.3.100.0020.01214.98
7.3.90.0050.01015.06
7.3.80.0050.01114.95
7.3.70.0050.00615.07
7.3.60.0050.01014.74
7.3.50.0060.00915.01
7.3.40.0090.00615.04
7.3.30.0070.00714.83
7.3.20.0050.01216.69
7.3.10.0080.00516.80
7.3.00.0060.00616.83
7.2.330.0070.01116.82
7.2.320.0100.01017.07
7.2.310.0040.01417.00
7.2.300.0130.00916.81
7.2.290.0100.01016.81
7.2.250.0060.01515.09
7.2.240.0090.01015.10
7.2.230.0100.00815.29
7.2.220.0050.00815.15
7.2.210.0030.01015.26
7.2.200.0060.01115.01
7.2.190.0090.00715.02
7.2.180.0070.01115.29
7.2.170.0030.01015.18
7.2.160.0070.00715.33
7.2.150.0070.01017.19
7.2.140.0070.00716.90
7.2.130.0070.00916.82
7.2.120.0050.00917.17
7.2.110.0050.00917.09
7.2.100.0080.00716.89
7.2.90.0010.01017.07
7.2.80.0070.00917.11
7.2.70.0090.00517.20
7.2.60.0710.00916.48
7.2.50.0600.01216.48
7.2.40.0580.00716.60
7.2.30.0540.00716.56
7.2.20.0550.00916.51
7.2.10.0600.00916.52
7.2.00.0080.00916.69
7.1.330.0050.00915.91
7.1.320.0100.00315.94
7.1.310.0060.00515.90
7.1.300.0030.00915.99
7.1.290.0060.00815.98
7.1.280.0070.00615.96
7.1.270.0090.00815.78
7.1.260.0030.01016.04
7.1.250.0050.01015.99
7.1.200.0040.01115.83
7.1.170.1540.00713.93
7.1.160.1520.01117.12
7.1.150.1520.01317.29
7.1.140.1750.01217.15
7.1.130.2250.01416.90
7.1.120.1940.01017.36
7.1.110.2020.00816.53
7.1.100.1970.01516.31
7.1.90.2110.00816.72
7.1.80.1370.01316.53
7.1.70.1290.01315.57
7.1.60.2040.01633.52
7.1.50.2530.01533.21
7.1.40.4090.01433.10
7.1.30.4310.02132.77
7.1.20.4290.02133.04
7.1.10.2600.00815.24
7.1.00.2760.01315.08

preferences:
61.69 ms | 400 KiB | 5 Q