I'm somewhat confused and was hoping you guys could help. I'm writing something simple that takes a value from the posted name field and returns it, checking to see beforehand that its a string(correct) or an integer(in which case it'll say 'a name is not a number').
<?php
$number = array("1","2","3","4","5","6","7","8","9","0");
if(!isset($_POST['submit'])){
?>
<p>Enter your name</p>
<form method="post" action="action4.php">
<input type="text" name="name">
<input type="submit" name="submit">
</form>
<?php
}else{
$name = $_POST['name'];
foreach($number as $v){
$int = (int)$v;
}
if($name == $int){
print "This is a number and not a name.";
}else{
print $name;
}
}
?>
Given that every number entered into the name field was seen as a string, I cycled through the array and converted every digit to an integer. When entering an integer into the name field however, rather than getting "this is a number and not a name" I get $name. Reciprocally if I enter in a string, I get "this is a number and not a name."
var_dumping both name and int in the if statement returns as expected: $name as string and $int as integer. So why are they comparing as true?