(PHP 3 >= 3.0.7, PHP 4, PHP 5)
Import variables into the current symbol table from an array
( array var_array [, int extract_type [, string prefix]] )
This function is used to import variables from an array into the
current symbol table. It takes an associative array
and treats keys as variable
names and values as variable values. For each key/value pair it
will create a variable in the current symbol table, subject to
Beginning with version 4.0.5, this function returns the number of
were introduced in version 4.2.0.
was introduced in version 4.3.0.
checks each key to see whether it
has a valid variable name. It also checks for collisions with
existing variables in the symbol table. The way invalid/numeric
keys and collisions are treated is determined by the
. It can be one of the
If there is a collision, overwrite the existing variable.
If there is a collision, don't overwrite the existing
If there is a collision, prefix the variable name with
Prefix all variable names with
. Beginning with PHP 4.0.5, this includes
numeric variables as well.
Only prefix invalid/numeric variable names with
. This flag was added in
Only overwrite the variable if it already exists in the
current symbol table, otherwise do nothing. This is useful
for defining a list of valid variables and then extracting
only those variables you have defined out of $_REQUEST, for
example. This flag was added in PHP 4.2.0.
Only create prefixed variable names if the non-prefixed version
of the same variable exists in the current symbol table. This
flag was added in PHP 4.2.0.
Extracts variables as references. This effectively means that the
values of the imported variables are still referencing the values of
parameter. You can use this flag
on its own or combine it with any other flag by OR'ing the
. This flag was added in PHP
is not specified, it is
assumed to be
is only required if
the prefixed result is not a valid variable name, it is not
imported into the symbol table.
returns the number of variables
successfully imported into the symbol table.
Do not use
on untrusted data, like
user-input ($_GET, ...). If you do, for example, if you want to run old
code that relies on
temporarily, make sure you use one of the non-overwriting
values such as
and be aware that you should extract
in that order.
A possible use for
is to import into the
symbol table variables contained in an associative array returned by
/* Suppose that $var_array is an array returned from
$size = "large";
$var_array = array("color" => "blue",
"size" => "medium",
"shape" => "sphere");
extract($var_array, EXTR_PREFIX_SAME, "wddx");
echo "$color, $size, $shape, $wddx_size\n";
The above example will output:
blue, large, sphere, medium
wasn't overwritten, because we
, which resulted in
being created. If
specified, then $wddx_size wouldn't even have been created.
would have caused
value "medium", and
would result in new variables
You must use an associative array, a numerically indexed array
will not produce results unless you use
Related Function(s) wddx_deserialize() compact()