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)
No comments:
Post a Comment