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

Reply via email to