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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hmdnawaz
Forum Newbie
Posts: 14
Joined: Tue Dec 21, 2010 10:55 pm

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

Post 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???
mellowman
Forum Commoner
Posts: 62
Joined: Sat Nov 22, 2008 5:37 pm

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

Post 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
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

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

Post 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.
hmdnawaz
Forum Newbie
Posts: 14
Joined: Tue Dec 21, 2010 10:55 pm

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

Post 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.
mellowman
Forum Commoner
Posts: 62
Joined: Sat Nov 22, 2008 5:37 pm

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

Post 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
Post Reply