-2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Practice4</title>
</head>
<body>
    <?php
            function calculate($number1,$number2)
            {
                $mult=$number1*$number2;
                define(num,$mult);
                return num;
            }
        echo "Number calculated is " . calculate(9,9);

?>

Please help me out with this.I am newbie to php.May i know can i return a Constant from a function if yes,Why am i getting Use of undefined constant num - assumed 'num' .

user5501265
  • 39
  • 1
  • 8

2 Answers2

0

The first argument of define() is a string. You need to quote num:

define('num',$mult);

define() definition

aynber
  • 22,380
  • 8
  • 50
  • 63
0

If you check the manual, you will know that you have incorrectly used the syntax.

Check the following code:

function calculate($number1,$number2)
{
    $mult=$number1*$number2;
    define('num',$mult);
    return num;
}
Sujeet Sinha
  • 2,417
  • 2
  • 18
  • 27