-1

the following code can't be worked. Though the function was calling

$name1 = "apple";
$gender1 = "orange";
$country1 = "pepe";

function profile1($name1, $gender1, $country1)
{

    echo $name1 . "\n";
    echo $gender1 . "\n";
    echo $country1 . "\n";
}
profile1();

1 Answers1

0

The function parameters $name1, $gender1, and $country1 are separate and distinct from the variables declared outside the function. When you call the function without providing any arguments, the values of the parameters will be undefined.

You can either:

profile1( $name1, $gender1, $country1 );

or (not recommended!):

function profile1()
{
global $name1, $gender1, $country1;
echo $name1 . "\n";
echo $gender1 . "\n";
echo $country1 . "\n";
}

profile1();
kmoser
  • 8,780
  • 3
  • 24
  • 40