Why do these return true:
ctype_alpha(74); // returns true
$bar = 74;
ctype_alpha($bar); // returns true
but this returns false:
$foo = [1,2,3,'74'];
ctype_alpha($foo[3]); // returns false
Why do these return true:
ctype_alpha(74); // returns true
$bar = 74;
ctype_alpha($bar); // returns true
but this returns false:
$foo = [1,2,3,'74'];
ctype_alpha($foo[3]); // returns false
Of the numeric values in your test array, only 74 is the ASCII code of a letter (J), but you have supplied that as a string, not an integer, so it will not be interpreted as a character. The integers 128, 127, and 64, do not correspond to any letters, which is why ctype_alpha
returns false for those. When you supply 74 as an integer value, then it does return true. ctype_alpha
is working fine.