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!! Link to comment https://forums.phpfreaks.com/topic/200368-php-code-help/ 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; } } Link to comment https://forums.phpfreaks.com/topic/200368-php-code-help/#findComment-1051520 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 Link to comment https://forums.phpfreaks.com/topic/200368-php-code-help/#findComment-1051522 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.