Jump to content

Archived

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

EriRyoutan

Get type of variable?

Recommended Posts

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?

Thanks

-Eri.

Share this post


Link to post
Share on other sites
Do you mean where a variable is an of a numric value or holds a string? You can do this:
[code]<?php

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

if(is_numeric($var))
{
    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)';
}

?>[/code]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.

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.