Jump to content


Get type of variable?

  • Please log in to reply
1 reply to this topic

#1 EriRyoutan

  • Members
  • PipPip
  • Member
  • 19 posts

Posted 16 April 2006 - 02:02 PM

I was working on a php script, and I came across a problem. ... I can't tell what type this variable is.

Does anybody know any easy ways to tell what type a variable is, without just trial and error?



#2 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 16 April 2006 - 02:13 PM

Do you mean where a variable is an of a numric value or holds a string? You can do this:

$var = "01256"; // $var is a numric value

    echo '$var is number!';
else if(is_string($var))
    echo '$var is a string!';
else if(is_bool($var))
    echo '$var is boolean (TRUE / FALSE)';

Ther are other is_* style functions in PHP like is_num, is_array, is_int etc.
Try changing the value of $var to $var = TRUE this time it'll say its a boolean variable.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users