phpSensei Posted August 16, 2007 Share Posted August 16, 2007 I need to know the correct way of doing something like this: <?php if(gettype($_POST['value']) != "int"){ die("Needs To Be an Interger"); } else { echo "..."; // Too Lazy To Come up with something; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65160-solved-using-the-gettype-in-if-conditions/ Share on other sites More sharing options...
cooldude832 Posted August 16, 2007 Share Posted August 16, 2007 For Post variables I think they are always interpreted as strings, But what a better idea in this case might be is to use a regex to see if its a number within your given value range. Quote Link to comment https://forums.phpfreaks.com/topic/65160-solved-using-the-gettype-in-if-conditions/#findComment-325318 Share on other sites More sharing options...
phpSensei Posted August 16, 2007 Author Share Posted August 16, 2007 Thanks, I got to the idea before I read your post lol.. You Helped anyways. Quote Link to comment https://forums.phpfreaks.com/topic/65160-solved-using-the-gettype-in-if-conditions/#findComment-325347 Share on other sites More sharing options...
keeB Posted August 16, 2007 Share Posted August 16, 2007 You can also do something like this, if not dealing with POST vars <?php // show a function which only accepts ints public function myFunction(int $i) { //code } public function myFunction2(array $b) { foreach ($b as $a) { //etc etc etc } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65160-solved-using-the-gettype-in-if-conditions/#findComment-325353 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.