3v4l.org

run code in 300+ PHP versions simultaneously
<?php $subscriberTags = json_decode('{"hu":2174325}'); $availableTags = json_decode('{"cz":2174305,"hu":2174325,"at":2174333,"de":2174353,"pl":2174365,"sk":2174373,"gb":2174381,"nl":2174385,"gr":2174877,"ru":2174881}'); $actualSubscriberTags = []; $addTags = []; $removeTags = []; foreach (['us', 'hu'] as $offer) { $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; }
Output for 7.4.0 - 7.4.2
Notice: Undefined variable: country in /in/e1Hmn on line 12 Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in /in/e1Hmn on line 14 Notice: Undefined variable: country in /in/e1Hmn on line 14 Notice: Undefined variable: country in /in/e1Hmn on line 14 Notice: Undefined variable: country in /in/e1Hmn on line 15 Notice: Undefined variable: country in /in/e1Hmn on line 12 Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in /in/e1Hmn on line 14 Notice: Undefined variable: country in /in/e1Hmn on line 14 Notice: Undefined variable: country in /in/e1Hmn on line 14 Warning: array_keys() expects parameter 1 to be array, object given in /in/e1Hmn on line 19 Warning: Invalid argument supplied for foreach() in /in/e1Hmn on line 19 Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in /in/e1Hmn on line 26 ADD TAG Fatal error: Uncaught Error: Cannot use object of type stdClass as array in /in/e1Hmn:28 Stack trace: #0 {main} thrown in /in/e1Hmn on line 28
Process exited with code 255.
Output for 7.2.0 - 7.2.27, 7.3.0 - 7.3.14
Notice: Undefined variable: country in /in/e1Hmn on line 12 Notice: Undefined variable: country in /in/e1Hmn on line 14 Notice: Undefined variable: country in /in/e1Hmn on line 14 Notice: Undefined variable: country in /in/e1Hmn on line 15 Notice: Undefined variable: country in /in/e1Hmn on line 12 Notice: Undefined variable: country in /in/e1Hmn on line 14 Notice: Undefined variable: country in /in/e1Hmn on line 14 Warning: array_keys() expects parameter 1 to be array, object given in /in/e1Hmn on line 19 Warning: Invalid argument supplied for foreach() in /in/e1Hmn on line 19 ADD TAG Fatal error: Uncaught Error: Cannot use object of type stdClass as array in /in/e1Hmn:28 Stack trace: #0 {main} thrown in /in/e1Hmn on line 28
Process exited with code 255.

preferences:
67.71 ms | 402 KiB | 51 Q