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. 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. Link to comment https://forums.phpfreaks.com/topic/7543-get-type-of-variable/#findComment-27464 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.