tronicsmasta Posted July 19, 2008 Share Posted July 19, 2008 hey guys... i have looked around and can't seem to find this answer... How can i return a variable for use from a function? eg: error(60); echo $err; //I want to use it here... function error($err) { print "Error $err"; return($err); //i want to use $err after i call the function } Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/115586-quick-function-help/ Share on other sites More sharing options...
wildteen88 Posted July 19, 2008 Share Posted July 19, 2008 To catch the value returned from a function, you need to do $err = error(60); Link to comment https://forums.phpfreaks.com/topic/115586-quick-function-help/#findComment-594191 Share on other sites More sharing options...
tronicsmasta Posted July 19, 2008 Author Share Posted July 19, 2008 i knew that... i was having a brain fart at 9:00am without my coffee lol thanks! Link to comment https://forums.phpfreaks.com/topic/115586-quick-function-help/#findComment-594203 Share on other sites More sharing options...
tronicsmasta Posted July 19, 2008 Author Share Posted July 19, 2008 one other quick question.... how can i return an array from a function or multiple variables from a function eg: From what I read the return function ends the function thus $bar wont be returned.... how can i do this ?!? echo $err; $multivar = func("blah"); function func($func) { $foo = "bar"; $bar = $func; return($foo); return($bar); } Link to comment https://forums.phpfreaks.com/topic/115586-quick-function-help/#findComment-594215 Share on other sites More sharing options...
paul2463 Posted July 19, 2008 Share Posted July 19, 2008 echo $err; $multivar = func("blah"); function func($func) { $returnArray[0] = "bar"; $returnArray[1] = $func; return $returnArray; } echo $multivar[0]; //prints out "bar" echo $multivar[1]; //prints out "blah" HTH Link to comment https://forums.phpfreaks.com/topic/115586-quick-function-help/#findComment-594221 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.