tags:

views:

151

answers:

5

Hello,

If I use PHP's extract() function to import a variable from an array, will a variable with the same name be overwritten? The reason I ask is because I'm trying to initialize all of my variables.

Thank you for your time.

+5  A: 

By default it will overwrite.

http://php.net/extract

If extract_type [the second argument] is not specified, it is assumed to be EXTR_OVERWRITE

See the linked page for other options

eyelidlessness
+1  A: 

This depends entirely on the extract_type value you use. The default, however, is to overwrite.

Michael Madsen
A: 

That depends on the second argument you pass to the function. extract() takes an optional second argument consisting of constants. See the docs at http://us2.php.net/manual/en/function.extract.php

fireeyedboy
+4  A: 

The default is to overwrite, however you can change this action to one of several possiblities, by telling the function how to handle collisions:

for example passing EXTR_SKIP as the second paramater e.g extract($array,EXTR_SKIP) will cause collisions to be skipped.

The full usage is detailed here : http://php.net/manual/en/function.extract.php

A: 

Thank you everybody. I only glazed over this info earlier and I hadn't to of even asked if I went to the manual and reviewed the function. Quick responses here :)

lanmind