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 Link to comment https://forums.phpfreaks.com/topic/8028-arrays-store-data-sa-strings-but-what-if-i-dont-want-that/ 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] Link to comment https://forums.phpfreaks.com/topic/8028-arrays-store-data-sa-strings-but-what-if-i-dont-want-that/#findComment-29321 Share on other sites More sharing options...
taps128 Posted April 21, 2006 Author Share Posted April 21, 2006 thanx Link to comment https://forums.phpfreaks.com/topic/8028-arrays-store-data-sa-strings-but-what-if-i-dont-want-that/#findComment-29378 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.