3v4l.org

run code in 300+ PHP versions simultaneously
<?php $emailDomain = 'subdomain.example.co.uk'; $domainParts = explode('.', $emailDomain); // The TLD will never be in the allow list, so we can pop it off first $domain = array_pop($domainParts); $listToCheck = []; foreach (array_reverse($domainParts) as $domainPart) { $domain = $domainPart .'.'. $domain; $listToCheck[] = $domain; } var_dump($listToCheck);

preferences:
24.47 ms | 407 KiB | 5 Q