Last Updated: September 09, 2019
·
3.332K
· sleekslush

Pythonic PHP ?

# python swap!
(a, b) = (b, a)    

// php swap!
list($a, $b) = array($b, $a);

8 Responses
Add your response

haha fun!

over 1 year ago ·

Really Pythonic would be to leave out the parentheses:

a, b = b, a

over 1 year ago ·

In PHP-5.4+ it will be

list($a, $b) = [$b, $a]

over 1 year ago ·

but there is no tuples in PHP

over 1 year ago ·

@djc Agreed :)

over 1 year ago ·

@mihailoff glad to see they are adopting that more common syntactic sugar

over 1 year ago ·

nice!

over 1 year ago ·

I found this out recently too! Returning multiple items is now so much nicer!

over 1 year ago ·