Building on Mikes’ hint that you look at using (int) to typecast to an integer, look at these examples:
$myVar[0]=12; // an int
$myVar[1]='1a'; // a string starting with an int
$myVar[2]='ab'; // a string with no ints
$myVar[3]='12'; // a string containing ints
$myVar[4]='a1'; // a string containing an int but starting with a non-int
$myVar[5]='1.8'; // a string containing a float
foreach( $myVar as $v)
echo (int)$v . '<br>';
// gives
12
1
0
12
0
1 // nb does not round up
Depending on what you want to do with the likes of “1a”, where PHP tries to analyse it as a number, finds a 1, thats OK, then finds an a, so drops it.
Whereas if the string starts with a non-numeric char “a1” it gives up and returns 0.
typical use:
if( (int)$var === 0) {
// failed the int test - send away
}else{
// passed the int test - get on processing
}
I use this a lot when I am expecting, say, a numerical id key to be passed from a form element. Short and sweet, and therefore memorable ;).
So you have got to be very clear in your mind what you want to happen in your middle test “1a”