The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Hello there. I've just stumbled accross something which is new for me. Slowly filling in my grand canyon of ignorance. Its the PHP function extract(). I haven't noticed anyone else using it in their code. I think it is useful where you loop through a result set of data. Here's an example.

So rather than messing with $row["foo"] and $row["bar"]
extract($row) places the array values into their own variables $foo and $bar, which I think is easier to work with when placing the variables inline into a string.

I've never seen that before, but I'll definitely use it in the future. Thanks for the tip

I looked it up in the PHP online manual and there are several other options for it, including specifying whether or not it over writes variables that have already been defined - you can also have it stick a prefix on the variable names if you want it to:

This is great. I thought that there must be a better way than all the silly, repetitive $row("foo") stuff and had it on my list to write a function. Now with the extract($row), maybe I won't have to. Amazing how sometimes when we struggle with things, we find out later that others are not doing it the way we are.