Re: [PHP] quick php for perl coder question
- From: jochem@xxxxxxxxxxxxx (Jochem Maas)
- Date: Thu, 11 Sep 2008 21:48:36 +0200
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 = 'joker@xxxxxxxxxxx';
$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 = 'joker@xxxxxxxxxxx';
$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
.
- Follow-Ups:
- Re: [PHP] quick php for perl coder question
- From: Sjoerd
- Re: [PHP] quick php for perl coder question
- References:
- quick php for perl coder question
- From: Thomas Bolioli
- quick php for perl coder question
- Prev by Date: Re: quick php for perl coder question
- Next by Date: Re: [PHP] quick php for perl coder question
- Previous by thread: Re: quick php for perl coder question
- Next by thread: Re: [PHP] quick php for perl coder question
- Index(es):
Relevant Pages
|