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???

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.