Mr. R Posted April 22, 2007 Share Posted April 22, 2007 Hi, here's a simple function to see if the variable is numeric. <?php $number = "5"; function test($number) { if (is_numeric($number)) { return true; }else{ return false; } } if (test($number) == "1") { echo "The function has returned true!"; } ?> If the variable "$number" is a number then the above will echo "The function has returned true!" There isnt really much difference or point but could you put something like "if test($number) returns true" rather than if test(number) =="1". This isnt important, i was just wondering lol. Thanks. Link to comment https://forums.phpfreaks.com/topic/48174-solved-function/ Share on other sites More sharing options...
genericnumber1 Posted April 22, 2007 Share Posted April 22, 2007 if(is_numeric($number)) { if(is_numeric($number) === true) { if(is_numeric($number) == true) { if(is_numeric($number) == 1) { if(is_numeric($number) !== false) { etc.... but why create a function that does the exact same thing as the function it's wrapping? Link to comment https://forums.phpfreaks.com/topic/48174-solved-function/#findComment-235506 Share on other sites More sharing options...
emehrkay Posted April 22, 2007 Share Posted April 22, 2007 hmmmm i would assume that the boolean true/false returns a number, but php is loosely typed and your comparison shouldnt matter. you could just do if(test($number)){ ... } to see what it returns, do var_dump(test($number)); but like generic said, is_numeric is a boolean function Link to comment https://forums.phpfreaks.com/topic/48174-solved-function/#findComment-235507 Share on other sites More sharing options...
Mr. R Posted April 22, 2007 Author Share Posted April 22, 2007 Ok thanks guys. Im not using this, just learning PHP and just wanna know everthing about it lol. Just tryin new things Link to comment https://forums.phpfreaks.com/topic/48174-solved-function/#findComment-235512 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.