Re: [PHP] quick php for perl coder question

2008-09-11 Thread Jochem Maas

Thomas Bolioli schreef:

I want to return an array from a function.
I have this:
return array($found, $username, $email, $nickname);
as my code. I have a bug in the code and I am not sure where yet. Should 
the above statement with this:


array($vars);


not sure what you meant with the line above, it's valid but does nothing.


   $vars = function($type, $abc, $xyz);
   $found = $vars[0];
   $username = $vars[1];
   $email = $vars[2];
   $nickname = $vars[3];

on the other end work? If so, then the bug is somewhere else.


yes this should work assuming you meant this:

?php

function foo() {
$found  = true;
$username   = 'The Joker';
$email  = '[EMAIL PROTECTED]';
$nickname   = 'joker';

return array($found, $username, $email, $nickname);
}

$vars   = foo();
$found  = $vars[0];
$username   = $vars[1];
$email  = $vars[2];
$nickname   = $vars[3];
?

although you could do it more perly:

?php

list($found, $username, $email, $nickname) = foo();

?

and maybe consider using an assoc array:

?php

function foo() {
$found  = true;
$username   = 'The Joker';
$email  = '[EMAIL PROTECTED]';
$nickname   = 'joker';

return array(
'found' = $found,
'username'  = $username,
'email' = $email,
'nickname'  = $nickname,
);
}

$vars   = foo();
// using an associative array negates the need to
// define the following variables, you can use
// $vars['found'] (etc) as it is quite descriptive
// in it's own right :-)
$found  = $vars['found'];
$username   = $vars['username'];
$email  = $vars['email'];
$nickname   = $vars['nickname'];

?


Thanks in advance,
Tom




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



Re: [PHP] quick php for perl coder question

2008-09-11 Thread Kirk . Johnson
Thomas Bolioli [EMAIL PROTECTED] wrote on 09/11/2008 01:10:18 PM:

 I want to return an array from a function.
 I have this:
 return array($found, $username, $email, $nickname);
 as my code. I have a bug in the code and I am not sure where yet. Should 

 the above statement with this:
 
 array($vars);
 $vars = function($type, $abc, $xyz);
 $found = $vars[0];
 $username = $vars[1];
 $email = $vars[2];
 $nickname = $vars[3];
 
 on the other end work? If so, then the bug is somewhere else.

You probably want:

$vars = array();

instead of:

array($vars);

which will throw an undefined variable error (if error reporting is turned 
up), but otherwise, yes, that should work.

Kirk

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