EriRyoutan Posted April 16, 2006 Share Posted April 16, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/7543-get-type-of-variable/ Share on other sites More sharing options...
wildteen88 Posted April 16, 2006 Share Posted April 16, 2006 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 valueif(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. Quote Link to comment https://forums.phpfreaks.com/topic/7543-get-type-of-variable/#findComment-27464 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.