4 ms·
PHP is sloppy and messy, and say what you will, but the first time I tried writing something like the below code I definitely had one of those "Woah. That is co
by technoguyrob 19y ago
PHP is sloppy and messy, and say what you will, but the first time I tried writing something like the below code I definitely had one of those "Woah. That is cool." moments like first-time experience with lambdas:
$a = 'var';
$b = 'iable';
$variable = 'var';
echo ${$a.$b};
Useful? Sure it is:
$filter = array("name", "email");
foreach($filter as $v) $$v = $_POST[$v];
- jmtulloss 19y agoI did a lot of this when I built a form templating engine a few years back. When I came back to the code a year later, I had no idea what I was doing. Python syntax is much cleaner, and with only one way to do things, it's almost always easier to read. I'm a Pythonista now.
- ijoshua 19y agoPython‘s way of accomplishing this is as easy, although the use of `locals` should indicate that this isn’t generally something you should be doing: post = {'name': 'ijoshua', 'email': 'spam@example.com', 'extra': 'data'} filter = ['name', 'email'] for k in filter: locals()[k] = post[k] print name, email