<?php
$strings = array('AbCd1zyZ9', 'foo!#$bar');
foreach ($strings as $testcase) {
    if (ctype_alnum($testcase)) {
        echo 'The string ', $testcase, ' consists of all letters or digits.', PHP_EOL;
    } else {
        echo 'The string ', $testcase, ' don\'t consists of all letters or digits.', PHP_EOL;
    }
}