Skip to content

Instantly share code, notes, and snippets.

@philsturgeon
Last active December 15, 2015 18:19
Show Gist options
  • Save philsturgeon/5302549 to your computer and use it in GitHub Desktop.
Save philsturgeon/5302549 to your computer and use it in GitHub Desktop.
Generating a 'X','Y' string from an array for an IN query with as little code as possible in Python and PHP. This is done as a learning exercise for me to see how list comprehensions work, being used for some random Twitter "your friends signed up" worker.
<?php
$users = [['id' => 1, 'name' => 'Jack'], ['id' => 2, 'name' => 'Jill']];
echo implode(',', array_map(function($u) { return "'{$u['id']}'"; }, $users));
users = [{'id': 1, 'name': 'Jack'}, {'id': 2, 'name': 'Jill'}];
print ','.join(["'{0}'".format(u['id']) for u in users])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment