3v4l.org

run code in 200+ PHP versions simultaneously
<?php $subscriberTags = json_decode('{"hu":2174325}', true); $availableTags = json_decode('{"cz":2174305,"hu":2174325,"at":2174333,"de":2174353,"pl":2174365,"sk":2174373,"gb":2174381,"nl":2174385,"gr":2174877,"ru":2174881}', true); $actualSubscriberTags = []; $addTags = []; $removeTags = []; foreach (['us', 'hu'] as $country) { $actualSubscriberTags[] = $country; if (!array_key_exists($country, $subscriberTags) && !in_array($country, $addTags)) { $addTags[] = $country; } } foreach (array_keys($subscriberTags) as $tag) { if (!in_array($tag, $actualSubscriberTags) && !in_array($tag, $removeTags)) { $removeTags[] = $tag; } } foreach ($addTags as $tag) { if (!array_key_exists($tag, $availableTags)) { echo 'ADD TAG ' . $tag . PHP_EOL; $availableTags[$tag] = 'created' . rand(0, 100); } echo 'ADD TO USER ' . $availableTags[$tag] . PHP_EOL; } foreach ($removeTags as $tag) { echo 'REMOVE FROM USER' . $availableTags[$tag] . PHP_EOL; }
based on tejfZ
Output for 7.4.2
ADD TAG us ADD TO USER created43
Output for 7.4.1
ADD TAG us ADD TO USER created30
Output for 7.3.3, 7.3.5, 7.4.0
ADD TAG us ADD TO USER created98
Output for 7.3.7, 7.3.14
ADD TAG us ADD TO USER created34
Output for 7.3.13
ADD TAG us ADD TO USER created81
Output for 7.3.12
ADD TAG us ADD TO USER created59
Output for 7.3.11
ADD TAG us ADD TO USER created6
Output for 7.2.23, 7.3.10
ADD TAG us ADD TO USER created85
Output for 7.3.9
ADD TAG us ADD TO USER created94
Output for 7.3.8
ADD TAG us ADD TO USER created72
Output for 7.2.18, 7.3.6
ADD TAG us ADD TO USER created45
Output for 7.3.4
ADD TAG us ADD TO USER created63
Output for 7.3.2
ADD TAG us ADD TO USER created20
Output for 7.3.1
ADD TAG us ADD TO USER created55
Output for 7.3.0
ADD TAG us ADD TO USER created66
Output for 7.2.27
ADD TAG us ADD TO USER created74
Output for 7.2.16, 7.2.26
ADD TAG us ADD TO USER created38
Output for 7.2.3, 7.2.6, 7.2.25
ADD TAG us ADD TO USER created17
Output for 7.2.24
ADD TAG us ADD TO USER created50
Output for 7.2.0, 7.2.22
ADD TAG us ADD TO USER created26
Output for 7.2.21
ADD TAG us ADD TO USER created19
Output for 7.2.20
ADD TAG us ADD TO USER created73
Output for 7.2.19
ADD TAG us ADD TO USER created92
Output for 7.2.17
ADD TAG us ADD TO USER created36
Output for 7.2.15
ADD TAG us ADD TO USER created79
Output for 7.2.14
ADD TAG us ADD TO USER created48
Output for 7.2.13
ADD TAG us ADD TO USER created0
Output for 7.2.11 - 7.2.12
ADD TAG us ADD TO USER created52
Output for 7.2.10
ADD TAG us ADD TO USER created87
Output for 7.2.9
ADD TAG us ADD TO USER created96
Output for 7.2.8
ADD TAG us ADD TO USER created21
Output for 7.2.7
ADD TAG us ADD TO USER created49
Output for 7.2.5
ADD TAG us ADD TO USER created2
Output for 7.2.4
ADD TAG us ADD TO USER created89
Output for 7.2.2
ADD TAG us ADD TO USER created82
Output for 7.2.1
ADD TAG us ADD TO USER created58