Page 1 of 1

How to get two values from a function in php???

Posted: Thu Dec 30, 2010 10:46 pm
by hmdnawaz
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???

Re: How to get two values from a function in php???

Posted: Thu Dec 30, 2010 10:53 pm
by mellowman
Wait what? Are you trying to pass two variable to "page 2" or pass two variables to a function.... i think you have to explain a little better on what you want to get done. :o

Re: How to get two values from a function in php???

Posted: Thu Dec 30, 2010 10:55 pm
by josh
You can return a single array containing two scalars on page 1.

Then store whatever values you need in a session, or pass it thru the query string to page 2.

Re: How to get two values from a function in php???

Posted: Thu Dec 30, 2010 11:02 pm
by hmdnawaz
I want to get the variable and the form on page2.php but in separate variables.
the function is in page1.php and i am calling the function in page2.php.

Re: How to get two values from a function in php???

Posted: Thu Dec 30, 2010 11:15 pm
by mellowman
I think your using the wrong terminology...what u need to use is an array where it stores both variable in on variable...hes an example...

Code: Select all

$variable[0] = "Variable 1";
$variable[1] = "Variable 2";
Now if you pass $variable to anther page via the POST method or storing in a session you can echo it out like this.

Code: Select all

echo $variable[0]; 
And you will get ---> Variable 1