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 vvaUv
Output for 7.4.2
ADD TAG us ADD TO USERcreated100
Output for 7.4.1
ADD TAG us ADD TO USERcreated92
Output for 7.4.0
ADD TAG us ADD TO USERcreated73
Output for 7.2.1, 7.3.14
ADD TAG us ADD TO USERcreated2
Output for 7.3.13
ADD TAG us ADD TO USERcreated74
Output for 7.3.12
ADD TAG us ADD TO USERcreated28
Output for 7.3.11
ADD TAG us ADD TO USERcreated26
Output for 7.3.10
ADD TAG us ADD TO USERcreated32
Output for 7.2.25, 7.3.9
ADD TAG us ADD TO USERcreated40
Output for 7.2.14, 7.3.8
ADD TAG us ADD TO USERcreated10
Output for 7.2.13, 7.3.7
ADD TAG us ADD TO USERcreated22
Output for 7.2.6, 7.2.21, 7.3.5 - 7.3.6
ADD TAG us ADD TO USERcreated21
Output for 7.3.4
ADD TAG us ADD TO USERcreated12
Output for 7.3.3
ADD TAG us ADD TO USERcreated35
Output for 7.3.2
ADD TAG us ADD TO USERcreated72
Output for 7.3.1
ADD TAG us ADD TO USERcreated5
Output for 7.2.18, 7.3.0
ADD TAG us ADD TO USERcreated11
Output for 7.2.27
ADD TAG us ADD TO USERcreated79
Output for 7.2.26
ADD TAG us ADD TO USERcreated0
Output for 7.2.16, 7.2.24
ADD TAG us ADD TO USERcreated31
Output for 7.2.23
ADD TAG us ADD TO USERcreated48
Output for 7.2.22
ADD TAG us ADD TO USERcreated90
Output for 7.2.2, 7.2.20
ADD TAG us ADD TO USERcreated27
Output for 7.2.5, 7.2.17, 7.2.19
ADD TAG us ADD TO USERcreated33
Output for 7.2.15
ADD TAG us ADD TO USERcreated77
Output for 7.2.12
ADD TAG us ADD TO USERcreated17
Output for 7.2.11
ADD TAG us ADD TO USERcreated49
Output for 7.2.4, 7.2.10
ADD TAG us ADD TO USERcreated83
Output for 7.2.9
ADD TAG us ADD TO USERcreated46
Output for 7.2.7 - 7.2.8
ADD TAG us ADD TO USERcreated85
Output for 7.2.3
ADD TAG us ADD TO USERcreated64
Output for 7.2.0
ADD TAG us ADD TO USERcreated39