Page 1 sur 1

Fonction retournant 2 valeurs

Posté : 06 mars 2006, 22:17
par Elie
Bonjour,

Imaginons une fonction :
function return() {
$b = 4;
$a = 3;

return $a, $b;

}

return();

echo "A = ".$a." B = ".$b;
Comment faire marcher ca ?

Posté : 06 mars 2006, 22:23
par jeff
salut essai un trus du genre
function retourne(&$a,&$b){
$a = $a*2;
$b =$b*3;
}

$a=1;
$b=3;

retourne($a,$b);

echo $a.'--'.$b;
je suis pas tres sur mais c'est le principe

Posté : 06 mars 2006, 23:21
par Cyrano
moauis, sinon, autre méthode : retourne un tableau de valeurs:
<?php
function mafonction()
{
    $a = 3;
    $b = 4;
    $tableau = array($a, $b);
    return $tableau;
}

$valeurs = mafonction();
echo("A = ". $valeurs[0] ."; B = ". $valeurs[1]);
?>

Posté : 06 mars 2006, 23:22
par Elie
Je vais suivre la methode Cyrano :)

Merci !