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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.