Search code examples
phpfunctionreturn

Basic PHP function returns a blank page


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;
            }
        ?>

Solution

  • To print to screen something like this will work:

    print_r(multiply($number1, $number2));