Pythonic PHP ?
# python swap!
(a, b) = (b, a)
// php swap!
list($a, $b) = array($b, $a);
Written by Craig Slusher
Related protips
8 Responses
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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# β Learn More
#native_title#
#native_desc#