What is "Extract" in PHP?

Asked

Viewed 1,465 times

10

I was running a code analysis PHP, and in a script used Extract.

I looked in some PHP documents and the examples are kind of abstract and unfortunately I didn’t notice much.

I would like to know in a general case what the Extract in PHP ? (If possible a concrete example).

  • Word of advice: avoid the extract. It’s not nice to make variables magically appear in a code file or, worse, function. It makes code harder to understand. If using this, at least document what is being imported.

  • 1

    It was for a specific need... However thanks for the tip, I will do research about it !

1 answer

13


Takes an associative array and declares variables, having as their name the keys, and the contents of the variable, the value of the array referring to the key.

Follow an example:

$teste = ["variavel" => "valor da variável"];

extract($teste);

echo $variavel;   //vai imprimir "valor da variavel"

http://php.net/manual/en/function.extract.php

Here are some very intuitive examples.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.