PHP Returning Multiple Values

Soldato
Joined
8 Oct 2005
Posts
4,184
Location
Midlands, UK
Lets say I have a simple function that queries a database for 4 values. If i want to return these four values for use on a page is the most efficient way to return these values as an array and use the list function? E.g

PHP:
function ocuk(1) {
//do database stuff
return array($1, $2, $3, $4);
}

//then on the actual page where IO need these vars
list($1, $2, $3, $4) = ocuk(1);

//etc.
Ta
 
Last edited:
Depend's what you wish to do with the data, you could return it as an ARRAY, OBJECT, JSON, XML the list could go on :)

ARRAY or OBJECT are the most common way you would want to do it in the example above.

(OBJECT = HASH/Associated Array)

Just stick the function response into a VAR and interface with it directly.

PHP:
    $val = ocuk();
    echo $val[0] . ' ' . $val[1];
 
Back
Top Bottom