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)) { $return = $this->baseService->createTag(self::LIST_ID_LANDLORDS, $tag); $availableTags[$tag] = $return['id']; } echo 'ADD ' . $availableTags[$tag] . PHP_EOL; } foreach ($removeTags as $tag) { echo 'REMOVE ' . $availableTags[$tag] . PHP_EOL; }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined variable $country in /in/BGZmP on line 12 Warning: Undefined variable $country in /in/BGZmP on line 14 Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, stdClass given in /in/BGZmP:14 Stack trace: #0 {main} thrown in /in/BGZmP on line 14
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Undefined variable $country in /in/BGZmP on line 12 Warning: Undefined variable $country in /in/BGZmP on line 14 Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, stdClass given in /in/BGZmP:14 Stack trace: #0 {main} thrown in /in/BGZmP on line 14
Process exited with code 255.
Output for 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
Notice: Undefined variable: country in /in/BGZmP on line 12 Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in /in/BGZmP on line 14 Notice: Undefined variable: country in /in/BGZmP on line 14 Notice: Undefined variable: country in /in/BGZmP on line 14 Notice: Undefined variable: country in /in/BGZmP on line 15 Notice: Undefined variable: country in /in/BGZmP on line 12 Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in /in/BGZmP on line 14 Notice: Undefined variable: country in /in/BGZmP on line 14 Notice: Undefined variable: country in /in/BGZmP on line 14 Warning: array_keys() expects parameter 1 to be array, object given in /in/BGZmP on line 19 Warning: Invalid argument supplied for foreach() in /in/BGZmP on line 19 Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in /in/BGZmP on line 26 Fatal error: Uncaught Error: Using $this when not in object context in /in/BGZmP:27 Stack trace: #0 {main} thrown in /in/BGZmP on line 27
Process exited with code 255.
Output for 7.3.32, 7.4.26
Warning: array_keys() expects parameter 1 to be array, object given in /in/BGZmP on line 19 Warning: Invalid argument supplied for foreach() in /in/BGZmP on line 19 Fatal error: Uncaught Error: Using $this when not in object context in /in/BGZmP:27 Stack trace: #0 {main} thrown in /in/BGZmP on line 27
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.3.33
Notice: Undefined variable: country in /in/BGZmP on line 12 Notice: Undefined variable: country in /in/BGZmP on line 14 Notice: Undefined variable: country in /in/BGZmP on line 14 Notice: Undefined variable: country in /in/BGZmP on line 15 Notice: Undefined variable: country in /in/BGZmP on line 12 Notice: Undefined variable: country in /in/BGZmP on line 14 Notice: Undefined variable: country in /in/BGZmP on line 14 Warning: array_keys() expects parameter 1 to be array, object given in /in/BGZmP on line 19 Warning: Invalid argument supplied for foreach() in /in/BGZmP on line 19 Fatal error: Uncaught Error: Using $this when not in object context in /in/BGZmP:27 Stack trace: #0 {main} thrown in /in/BGZmP on line 27
Process exited with code 255.

preferences:
175.98 ms | 402 KiB | 178 Q