Archive for September, 2009

PHP – array_map + create_function

Sunday, September 20th, 2009

For use with php < 5.3. If you're using 5.3 just use a proper anonymous function.

array_map(create_function(‘$v’, ‘return strtolower($v).”s”;’), $a);

Python eval

Monday, September 7th, 2009

Generally, just use ‘exec’ statement instead of the ‘eval’ function

v = 1
exec 'v = 2'
print v

Python eval is a function meaning it doesn’t allow setting of variables. Usage is:
x = 1
print eval(‘x+1′)