As I was finalizing some tweaks to a social networking script for a client, I noticed an interesting way that variables are pulled off the db record set which I didn't know of previously.
extract((array)$row,EXTR_PREFIX_ALL,"row");
This takes all the variables within the $row array, which I would typically access by $row[varname] and creates a variable called $row_varname. Pretty neat!
I had previously done something similar to this by looping through the array and assiging $GLOBALS[varname] = $value, but this neat little sucker does all that for us, now doesn't it!
Subscribe to:
Post Comments (Atom)
Friday, July 7, 2006
An easy way to loop through db records
As I was finalizing some tweaks to a social networking script for a client, I noticed an interesting way that variables are pulled off the db record set which I didn't know of previously.
extract((array)$row,EXTR_PREFIX_ALL,"row");
This takes all the variables within the $row array, which I would typically access by $row[varname] and creates a variable called $row_varname. Pretty neat!
I had previously done something similar to this by looping through the array and assiging $GLOBALS[varname] = $value, but this neat little sucker does all that for us, now doesn't it!
extract((array)$row,EXTR_PREFIX_ALL,"row");
This takes all the variables within the $row array, which I would typically access by $row[varname] and creates a variable called $row_varname. Pretty neat!
I had previously done something similar to this by looping through the array and assiging $GLOBALS[varname] = $value, but this neat little sucker does all that for us, now doesn't it!
Subscribe to:
Post Comments (Atom)
Kalen Jordan provides advice, tools, tips and tricks for freelance designers, developers, and other tech professionals who are looking to grow their business. Feel free to
youtube
No comments:
Post a Comment