php - Returning 2 values from a function -


this question has answer here:

is possible return 2 values when calling function output values, example, have this:

<?php  function ids($uid = 0, $sid = '') {     $uid = 1;     $sid = md5(time());      return $uid;     return $sid;     }  echo ids();  ?> 

which output 1, want chose ouput, e.g. ids($sid), still output 1.

is possible?

you can return 1 value. can use array contains other 2 values:

return array($uid, $sid); 

then access values like:

$ids = ids(); echo $ids[0];  // uid echo $ids[1];  // sid 

you use associative array:

return array('uid' => $uid, 'sid' => $sid); 

and accessing it:

$ids = ids(); echo $ids['uid']; echo $ids['sid']; 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -