xfezz Posted December 29, 2006 Share Posted December 29, 2006 function one($y,$z) {[b]xyz[/b] = some query from the database;some other calculations using variables $y and $z;}function two($yy,$zz) {some other calculations using variables $yy and $zz;newVar = [b]xyz[/b]+ 4;}I need to use variable xyz to do a calculation in function two. how do I pass one variable to another function? or would I have to run the same query again in function two? Quote Link to comment Share on other sites More sharing options...
trq Posted December 29, 2006 Share Posted December 29, 2006 A few ways...Either call function two within function one, or return $xyz as a result of function one and pass it into function two that way.Of couse you could also use globals but I wouldn't recommend it. Quote Link to comment Share on other sites More sharing options...
play_ Posted December 30, 2006 Share Posted December 30, 2006 [code][code]<?function Add($x, $y) { $result = $x + $y; return $result;}function Subtract($returnedRESULT) { echo $returnedRESULT;}$returnedRESULT = Add(2, 3);Subtract($returnedRESULT);?>[/code]I don't know if more than one value can be passed. maybe if you put them in an array? [/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.