[PHP] return multiple value from function

2002-04-29 Thread sanjay

Hi List,

I am new to php programming and wanted to know if it is possible to return
multiple value from a function like cgi programs.
How can I get the following result using php.

($var1, $var2) = myfunction($a,$b);


function myfunction($c,$d)
{
   // code
// code
return ($e,$f);
}


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] return multiple value from function

2002-04-29 Thread Cal Evans

no, it's not possible to do it that way.  If you need to return multiple
values from a function, your best bet is to return an array or some kind of
record structure.

By design, in almost all languages, functions only return a single value.
=C=

*
* Cal Evans
* Journeyman Programmer
* Techno-Mage
* http://www.calevans.com
*


-Original Message-
From: sanjay [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 29, 2002 9:11 AM
To: [EMAIL PROTECTED]
Subject: [PHP] return multiple value from function


Hi List,

I am new to php programming and wanted to know if it is possible to return
multiple value from a function like cgi programs.
How can I get the following result using php.

($var1, $var2) = myfunction($a,$b);


function myfunction($c,$d)
{
   // code
// code
return ($e,$f);
}


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] return multiple value from function

2002-04-29 Thread Richard Emery

?php
function funca($a,$b)
{
$q=$a;
$w=$b;
return array($w,$q);
}

$e=123;
$r=456;

list($z,$x) = funca($e,$r);
print $z, $x\n;
?

- Original Message - 
From: sanjay [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, April 29, 2002 9:11 AM
Subject: [PHP] return multiple value from function


Hi List,

I am new to php programming and wanted to know if it is possible to return
multiple value from a function like cgi programs.
How can I get the following result using php.

($var1, $var2) = myfunction($a,$b);


function myfunction($c,$d)
{
   // code
// code
return ($e,$f);
}


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] return multiple value from function

2002-04-29 Thread Jason Wong

On Monday 29 April 2002 22:11, sanjay wrote:
 Hi List,

 I am new to php programming and wanted to know if it is possible to return
 multiple value from a function like cgi programs.
 How can I get the following result using php.

 ($var1, $var2) = myfunction($a,$b);


 function myfunction($c,$d)
 {
// code
 // code
 return ($e,$f);
 }

No. But it is possible to get similar results.

a) Return an array

  $result = myfunction($a, $b);
  echo $result['e'];
  echo $result['f'];


  function myfunction($c, $d) {
do
something
$result['e'] = $this_is_e;
$result['f'] = $this_is_f;
return $result;
  }


b) Use references

  myfunction($c, $d, $e, $f);

  echo $e;
  echo $f;
 
  function myfunction($c, $d, $e, $f) {
do
something
$e = $this_is_e;
$f = $this_is_f;
  }

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
I didn't know it was impossible when I did it.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] return multiple value from function

2002-04-29 Thread 1LT John W. Holmes

Best you can do is return an array and call it like this:

function myfunction($a,$b)
{
$r[0] = $a + 1;
$r[1] = $b + 1;
return $r;
}

list($c,$d) = myfunction(10,20);

Adapt to your needs.

---John Holmes...

- Original Message -
From: sanjay [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, April 29, 2002 10:11 AM
Subject: [PHP] return multiple value from function


 Hi List,

 I am new to php programming and wanted to know if it is possible to return
 multiple value from a function like cgi programs.
 How can I get the following result using php.

 ($var1, $var2) = myfunction($a,$b);


 function myfunction($c,$d)
 {
// code
 // code
 return ($e,$f);
 }


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] return multiple value from function

2002-04-29 Thread sanjay

Thnaks. It solved my problem.

sanjay

- Original Message - 
From: Jason Wong [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, April 29, 2002 7:50 PM
Subject: Re: [PHP] return multiple value from function


On Monday 29 April 2002 22:11, sanjay wrote:
 Hi List,

 I am new to php programming and wanted to know if it is possible to return
 multiple value from a function like cgi programs.
 How can I get the following result using php.

 ($var1, $var2) = myfunction($a,$b);


 function myfunction($c,$d)
 {
// code
 // code
 return ($e,$f);
 }

No. But it is possible to get similar results.

a) Return an array

  $result = myfunction($a, $b);
  echo $result['e'];
  echo $result['f'];


  function myfunction($c, $d) {
do
something
$result['e'] = $this_is_e;
$result['f'] = $this_is_f;
return $result;
  }


b) Use references

  myfunction($c, $d, $e, $f);

  echo $e;
  echo $f;
 
  function myfunction($c, $d, $e, $f) {
do
something
$e = $this_is_e;
$f = $this_is_f;
  }

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
I didn't know it was impossible when I did it.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php