Returning 2 Values from a Function

Source: https://stackoverflow.com/questions/3815234/returning-2-values-from-a-function

You can use an array that itself contains the other two values:
return array($uid, $sid);
Then you access the values like:
$ids = ids();
echo $ids[0];  // uid
echo $ids[1];  // sid

You could also use an associative array:
return array('uid' => $uid, 'sid' => $sid);
And accessing it:
$ids = ids();
echo $ids['uid'];
echo $ids['sid'];


Post a Comment

0 Comments