Functions
WebDev/*nix assorted functions & hacks
Search
find all
Array
-
Bash
-
Classes
-
Config
-
DateTime
-
Debug
-
dotjs
-
File
-
foooo
-
Git
-
HTML
-
Images
-
Javascript
-
Linux
-
Math
-
Misc
-
MySQL
-
OS X
-
Reading
-
Redis
-
Shell scripts
-
snippets
-
SQL
-
Strings
-
TextMate
-
Web
-
\(^o^)/ Fun!
-
_Misc hacks
-
_Pages
snippets
.htaccess / mod_rewrite
404 header
Ajax response page
Basic HTTP Auth
Column display sans near-empty columns
JavaScript favelets/bookmarklets
misc php stuffs
php tricks
8
found
auth
Name:
Category: snippets
Body:
list($a, $b) = array($b, $a); # any number of vars works, obviously # nested lists fill variables from multidim arrays: $arr = array( array('aaaa', 'bbb'), array('cc', 'd') ); list(list($a, $b), list($c, $d)) = $arr; echo "$a $b $c $d"; // aaaa bbb cc d # list() values to arrays while (list($arr1[], $arr2[], $arr3[]) = mysql_fetch_row($res)) { .. } # or get columns from a matrix foreach($data as $row) list($col_1[], $col_2[], $col_3[]) = $row; # replace all occurrences of #foo# by $foo in the input file $func = create_function('$str', 'return $GLOBALS[substr($str[0], 1, -1)];') $message = preg_replace_callback('/(#[A-Za-z]+#)/', $func, file_get_contents('message_template.txt')); # abusing the ternary operator to set other variables as a side effect: $foo = $condition ? 'Yes' . (($bar = 'right') && false) : 'No' . (($bar = 'left') && false); # boolean False cast to string for concatenation becomes an empty string ''. # you can also use list() but that is so boring.. list($foo, $bar) = $condition ? array('Yes', 'right') : array('No', 'left'); # use glob() with basename to get a directory listing without the paths # sorta like scandir() only for php4 $files = array_map('basename', glob('../some_dir/*')); # gets list of user defined functions: print_r(array_pop(get_defined_functions())); # better but longer: $foo = get_defined_functions(); print_r($foo['user']);
Footer