blueman Posted December 16, 2006 Share Posted December 16, 2006 if i enter number into a form, what type of data type is it in php (string or int)? and, one more question: is there a difference between [color=red]if($_POST["variable"])}[/color]and [color=red]if(isset($_POST["variable"]){}[/color]thanks Link to comment https://forums.phpfreaks.com/topic/30860-data-type-in-a-form/ Share on other sites More sharing options...
Hypnos Posted December 16, 2006 Share Posted December 16, 2006 Yeah. is_int or is_numeric, depending on what kind of numbers you're working with. If it isn't a number, it's obviously a string. Link to comment https://forums.phpfreaks.com/topic/30860-data-type-in-a-form/#findComment-142292 Share on other sites More sharing options...
Albright Posted December 16, 2006 Share Posted December 16, 2006 Hypnos, your answer doesn't seem to be relevant to the questions...All elements $_POST (excluding file uploads, where things start to get funky) are string variables. This includes things you'd expect to be only boolean, such as check boxes; when checked, the data will look like $_POST['checkbox']=="on".if($var) is functionally equivalent to if($var==true) (though I believe the latter actually consumes more processor cycles, because the computer has to make two boolean checks instead of one... first it checks if $var is true, then it checks if it's true that $var is true, if that makes any sense). isset($var) returns true if a variable exists that is named $var.[code]<?phperror_reporting(E_ALL);//Let's turn on error reporting because we are smartif(isset($var)){ echo("Set"); }else{ echo("Not Set"); }//Will output "Set"$var=false;if(isset($var)){ echo("Set"); }else{ echo("Not Set"); }//Will output "Not Set"if($var){ echo("True"); }else{ echo("False"); }//Will output "false"unset($var);if($var){ echo("True"); }else{ echo("False"); }/*Will cause an "Undefined Variable" error...but would print "False" if we were dumb and didn't turn on full error reporting*/?>[/code] Link to comment https://forums.phpfreaks.com/topic/30860-data-type-in-a-form/#findComment-142315 Share on other sites More sharing options...
Hypnos Posted December 16, 2006 Share Posted December 16, 2006 The question was changed. The original question as I read it was how to tell if a var was a string or number.[quote author=blueman link=topic=118855.msg485996#msg485996 date=1166255244]and, one more question: is there a difference between [color=red]if($_POST["variable"])}[/color]and [color=red]if(isset($_POST["variable"]){}[/color][/quote]There is a difference between if(isset($var)) and if($var). In my experence isset is more sensitive to throw a true.Here is an example.[code=php:0]<?php$a = "";if($a) print "if(\$a) says \$a is set. \n";else print "if(\$a) says \$a is not set. \n";if(isset($a)) print "isset(\$a) says \$a is set. \n";else print "isset(\$a) says \$a is not set. \n";?>[/code]It will output:if($a) says $a is not set.isset($a) says $a is set. Link to comment https://forums.phpfreaks.com/topic/30860-data-type-in-a-form/#findComment-142586 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.