php functions within functions?

question asker

New member
The other page must be included (or required) before it's functions are called. The variables must also be declared global in both functions.. e.g.


// page1.php

<?php

require_once("page2.php");

firstFunction();

function firstFunction() {
global $x, $y;
secondFunction();
echo $x . ", " . $y;
}

?>

// page2.php

<?php

function secondFunction() {
global $x, $y;
$x = 5;
$y = 10;
}

?>

Good luck!
 
So i have one php script that is mostly one function... in this function it requires another script and calls functions from it. Now I cannot get the first script to see variables made by the required functions even with global. So is there a way to have a function, call a function from another script and allow the first script to use the variables the second produces?

thanks
 
The other page must be included (or required) before it's functions are called. The variables must also be declared global in both functions.. e.g.


// page1.php

<?php

require_once("page2.php");

firstFunction();

function firstFunction() {
global $x, $y;
secondFunction();
echo $x . ", " . $y;
}

?>

// page2.php

<?php

function secondFunction() {
global $x, $y;
$x = 5;
$y = 10;
}

?>

Good luck!
 
Back
Top