Jump to content


Photo

is_numeric() does not work properly


  • Please log in to reply
5 replies to this topic

#1 thedust2010

thedust2010
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 07 September 2006 - 06:14 PM

Can anyone explain the following output to me?

if ($value1 == "0") {
     echo "AAA<br>";
}
if (is_numeric("0")) {
     echo "BBB<br>";
}
if (is_numeric(0)) {
     echo "CCC<br>";
}
if (is_numeric(trim($value1))) {
     echo "DDD<br>";
}

Output is:

AAA
BBB
CCC

Why on earth do I not see "DDD"?  I've tried with and without trim().  Doesn't make a difference.  This has got to be a bug of some sort.

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 07 September 2006 - 06:28 PM

works ok for me. i'm on PHP 4.3.10 here

edit: gave it a blast on 5.0.5 too, works fine there too.
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 07 September 2006 - 06:31 PM

It should output
BBB
CCC
since $value is not defined.

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 07 September 2006 - 06:32 PM

I'm starting off with

$value1 = "0";

followed by your code and I get AAA,BBB,CCC and DDD.

What value are you starting with?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 07 September 2006 - 06:34 PM

ran the same results without defining $value1, on both 4.3.10 and 5.0.5.
got BBB and CCC, as you wanted.
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#6 thedust2010

thedust2010
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 07 September 2006 - 06:44 PM

Arrrgh... OK I got it.  I am cycling through an array and was checking the value instead of the key.  I am very sorry.  Thanks for all the quick responses but I just totally missed this.  I think I will try to get more sleep tonight.  :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users