Jump to content

PHP code help


SpikedUDE

Recommended Posts

Please write a PHP function using valid syntax. The function should be named "squared" and it should accept one parameter, called "$number". The function should first check if the parameter is a numeric value (an integer or floating point number, or a string containing a number). If not, it should return the boolean False. If it is numeric, it should return a value equal to the number sqared (the number times itself).

 

If anyone can help will appreciate it vey much!!! Thanks guys!!

Link to comment
https://forums.phpfreaks.com/topic/200368-php-code-help/
Share on other sites

This doesn't check if there is a number in the string.

What you'd need to do for that is.. remove all the letters, leaving only numbers.. and then go through with the is_numeric() section.

 

function myfunc($number) {
    if (is_numeric($number)) {
        $number = $number * $number;
        return $number;
    } else {
       return false;
    }
}

Link to comment
https://forums.phpfreaks.com/topic/200368-php-code-help/#findComment-1051520
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.