Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP's extract() Function

Tags:

php

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.

like image 664
lanmind Avatar asked Sep 02 '26 05:09

lanmind


2 Answers

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

like image 135
eyelidlessness Avatar answered Sep 03 '26 20:09

eyelidlessness


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

like image 29
Gavin Avatar answered Sep 03 '26 18:09

Gavin