PHP extract () function

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 am asking is because I am trying to initialize all of my variables.

Thank you for your time.

+2


source to share


4 answers


It will be overwritten by default.

http://php.net/extract



If extract_type

[second argument] is not specified, it is assumed thatEXTR_OVERWRITE

See linked page for other options

+5


source


The default is overwrite, but you can change this to one of several possible options by specifying a collision handling function:

for example pass EXTR_SKIP

, since the second parameter, for example extract($array,EXTR_SKIP)

, will skip collisions.



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

+4


source


It depends entirely on the extract_type value you are using. However, the default needs to be overwritten.

+1


source


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

0


source







All Articles