By Samat Jain
October 29, 2008 - 3:55pm
Python provides a neat way for functions to return multiple arguments via “tuple unpacking”. For example:
def blah:
return ('one', 'two')
rval_1, rval_2 = blah()
The same can be done in PHP relatively easily via the list construct:
function blah()
{
return array('one', 'two'); }
list($rval_1, $rval_2) = blah();
Like this article? Please support my writing! Flattr my blog (see my thoughts on Flattr), tip me via PayPal, or send me an item from my Amazon wish list.
Want to see more of my writing? Subscribe to
Samat Says' RSS feed







Comments
Permalink influx on October 29, 2008 - 6:46pm wrote…
Why not just use Python :(
Permalink Samat Jain on November 1, 2008 - 2:29am wrote…
Unfortunately, this was part of a larger application written in PHP. Why would anyone use PHP if they weren’t stuck with it?
It’s really sort of funky that I apply Python idioms to PHP and Java. I like to think my code is more concise and makes sense to me, but less so to people who only do PHP or Java and not Python… how many times do you see people using PHP’s list construct?