Jump to content

Archived

This topic is now archived and is closed to further replies.

taps128

Arrays store data sa strings, but what if I don't want that?

Recommended Posts

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.