Jump to content

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


hmdnawaz

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.