0

I am trying to do function overloading in PHP and I want to make the return value of a function into a variable. But if I do

<?php
include("functions.php");
func();
echo $add;
?>

in my index.php file and

<?php
function func() {
    $add = 1+2;
    return $add;
}
?>

in my functions.php file it gives me an undefined variable error. How do I fix this?

EngEa
  • 1
  • `$add` only exists within the scope of the function. You're returning it the variable, but not assigning the return value to anything. You can use `$add = func();` to have`$add` within the scope, or you can name that variable to anything you want. – aynber Aug 27 '21 at 14:12

0 Answers0