In PHP 4.3.11 (not sure about other versions), this function can provide erratic behavior. Though we normally expect automatic type casting to do the work for us, in these ctype functions, you must do it yourself!
Example:
<?php
echo '<pre>';
$fields[0] = 'somestring';
$fields[1] = 150679;
$fields[2] = 20050912;
var_dump($fields);
if(!ctype_digit($fields[1])) echo "1 not digits\n";
if(!ctype_digit($fields[2])) echo "2 not digits\n";
var_dump($fields);
echo '</pre>';
?>
Returns:
array(3) {
[0]=>
string(10) "somestring"
[1]=>
int(150679)
[2]=>
int(20050912)
}
array(3) {
[0]=>
string(10) "somestring"
[1]=>
string(8) "20050912"
[2]=>
int(20050912)
}
Notice that the value in $fields[2] was converted to a string and moved to $fields[1]! Explicitly converting the values to strings solved the problem.