Reputation: 119
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.
Upvotes: 2
Views: 697
Reputation: 2183
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 parameter 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
Upvotes: 4
Reputation: 63519
By default it will overwrite.
If
extract_type
[the second argument] is not specified, it is assumed to beEXTR_OVERWRITE
See the linked page for other options
Upvotes: 6
Reputation: 22783
That depends on the second argument you pass to the function. extract() takes an optional second argument consisting of constants. See the docs at https://www.php.net/manual/en/function.extract.php
Upvotes: 0
Reputation: 55009
This depends entirely on the extract_type value you use. The default, however, is to overwrite.
Upvotes: 1