-1

I'm learning PHP for the first time and this exercise gives back a blank page. I don't understand why, it's just defining two functions (number 1 and 2), then multiplying both, then printing on screen the result.

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <?php
        $number1 = 1;
        $number2 = 2;
        function multiply($number1, $number2)
        {
            $result = ($number1 * $number2);
            return $result;
        }
?>
    </body>
</html>

Same with another function, it's supposed to print a Hello world string, yet another blank page.

        <?php
            $head = "Hello world PHP";
            function header($head)
            {
                return $head;
            }
        ?>
azure_sky
  • 13
  • 1
  • 3
    Both these functions return a value and don't display anything, you also don't actually call the functions either. – Nigel Ren May 16 '20 at 16:15
  • 1. Returning from a function is not same as printing. 2. You have defined your function but you haven't `called` them. Functions are used for solving a particular task. And they should be called to execute. Eg: `multiply(1, 2)` 3. As a beginner you should search for a Free PHP course and get the basics right and strong. Then only you can build on top of that. There are tons of tutorials available online (Youtube, Udemy etc). – Harish ST May 16 '20 at 16:23
  • That makes sense, thanks for the input! – azure_sky May 17 '20 at 13:01

1 Answers1

0

To print to screen something like this will work:

print_r(multiply($number1, $number2));
philb
  • 46
  • 1
  • 3