hmdnawaz Posted December 31, 2010 Share Posted December 31, 2010 I have two pages of php. one is page1.php and the other is page2.php. In page1.php there is a function which dynamically creates a form of html and return the full form at the end of the function. And I want to the function to return a 2nd variable with the form. and i get that variable on page2.php. How can i do this??? Link to comment https://forums.phpfreaks.com/topic/223056-how-to-get-two-values-from-a-function-in-php/ Share on other sites More sharing options...
tqla Posted December 31, 2010 Share Posted December 31, 2010 Read up on sessions here: http://www.tizag.com/phpT/phpsessions.php Link to comment https://forums.phpfreaks.com/topic/223056-how-to-get-two-values-from-a-function-in-php/#findComment-1153257 Share on other sites More sharing options...
kenrbnsn Posted December 31, 2010 Share Posted December 31, 2010 In order to have a function return more than one value you need to return the values in an array and then get the returned values from the array: <?php function twovals() { $firstval = 'This is the first value'; $second = 'This is the second value'; return (array($firstval,$second)); } list($val1,$val2) = twovals(); echo '$val1: ' . $val1 . ' --- $val2: ' . $val2; ?> Ken Link to comment https://forums.phpfreaks.com/topic/223056-how-to-get-two-values-from-a-function-in-php/#findComment-1153260 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.