Since in PHP you don't declare variable types, PHP does its best to guess what you mean with your values and integers have preference to strings, so your '01' gets converted to a plain integer 1 for the comparison.

Use === (triple) equal in the comparison and it will check for both value AND type and it won't do any type conversion.

Satyam


----- Original Message ----- From: "Arno Coetzee" <[EMAIL PROTECTED]>
To: "php-general" <php-general@lists.php.net>
Sent: Monday, March 12, 2007 8:26 AM
Subject: [PHP] Data Types Problem


Hi Guys

I seem to have a problem with data types in php

when executing the following script , i do not get the desired output.

i a pass url parameter (message) to the script.

if i pass a numeric value (1) , the script accepts it as '01' and vice versa.
the same with 0 and '00'

here is the script:

<?php
   $theMessage = $_REQUEST['message'];
  echo "theMessage : '" . $theMessage . "'\n";
  if ($theMessage == "01")
   {
       echo "message : '01'";
   }else if ($theMessage == "00")
   {
       echo "message : '00'";
   }else if (is_numeric($theMessage))
   {
        echo "Numeric Input : " . $theMessage;
   }else
   {
       echo "Invalid Input";
   }
?>

i presume that i am not interpreting the data types it should be interpreted.

can anyone please help

--
Arno Coetzee
Flash Media Group
Developer
Mobile : 27 82 693 6180
Office : 27 12 430 7597

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.8/718 - Release Date: 11/03/2007 9:27



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to