taps128 Posted April 21, 2006 Share Posted April 21, 2006 I fill an array with data collected from a webpage form it looks like this: while ($a<$redovi) {d $pk="proizvedeno_komada".$a; $sp="sifra_proizvoda".$a; $proizvedeno_komada[]=$_POST[$pk]; $sifra_proizvoda[]=$_POST[$sp]; $a++; }And since only integers can be stored inside $proizvedeno_komada, I want to produce a "You can't do that" message if the user entered anything else besides an integer.When I entered only integers the gettype() function echoed string for all of them my checking function goes like this :function kontrola_niza($niz) { $a=array_merge($niz); foreach ($a as $value){ if (is_integer($value)==FALSE) {$r=0;return $r; break;} } $r=1; return $r; }I appriciate all the help you can give me.Nikola Quote Link to comment Share on other sites More sharing options...
sonjay Posted April 21, 2006 Share Posted April 21, 2006 The "numbers" that come in through your $_POST values are always POSTed as strings, even if they're numbers.You need to use PHP's is_numeric() function instead of is_integer(). You can also cast your POSTed values as integers before doing anything with them: [code]$val = intval($val);[/code] Quote Link to comment Share on other sites More sharing options...
taps128 Posted April 21, 2006 Author Share Posted April 21, 2006 thanx Quote Link to comment 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.