In PHP I have 3 variables set like this...
$myVariable1 = '2345';
$myVariable2 = 4433;
$myVariable3 = 'test';
I am trying to ensure that these are all integers and if not then I would like to set them as blank. I have read up on is_numeric but am not sure if this is the correct function to use.
if (!is_numeric($myVariable1)) {
$myVariable1 = 2345;
}
if (is_numeric($myVariable2)) {
$myVariable2 = 4433;
}
if (!is_numeric($myVariable3)) {
$myVariable3 = NULL;
}
Is there a way to do this automatically so it will attempt to cast to an integer or set NULL if not able to?