Jump to content

[SOLVED] function


Mr. R

Recommended Posts

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

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

Archived

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

×
×
  • Create New...

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.