SpikedUDE Posted May 1, 2010 Share Posted May 1, 2010 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!! Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 1, 2010 Share Posted May 1, 2010 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; } } Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted May 1, 2010 Share Posted May 1, 2010 This looks like an assignment to me. It's VERY easy. I'm sure if you just read the manual on functions you could do this yourself http://www.php.net/manual/en/functions.user-defined.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.