Last Updated: September 09, 2019
·
3.613K
· 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 ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#php
#python
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside