lanmind
lanmind

Reputation: 119

PHP's 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 ask is because I'm trying to initialize all of my variables.

Thank you for your time.

Upvotes: 2

Views: 697

Answers (4)

Gavin
Gavin

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

eyelidlessness
eyelidlessness

Reputation: 63519

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

Upvotes: 6

Decent Dabbler
Decent Dabbler

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

Michael Madsen
Michael Madsen

Reputation: 55009

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

Upvotes: 1

Related Questions