Php extract function

Source: Internet
Author: User

Extract
(PHP 4 and PHP 5)

Extract-import to the current variable symbol table from an array

Description
Extract (array $ var_array [Abstract $ extract_type = EXTR_OVERWRITE [, string $ prefix])
Imports an array of variables to the current symbol table.

Check every key to see if it has a valid variable name. It also checks the collision with the existing variable symbol table.

Parameters

Var_array
Join array. This function uses the key as the variable name and value as the variable value. For each key/value pair, a variable is created in the current symbol table, but extract_type and prefix parameters are required.

You must use an associated array. A numeric index array will not produce results unless you use EXTR_PREFIX_ALL or EXTR_PREFIX_INVALID.

Extract_type
Invalid mode/number keys and collisions are handled by extract_type. It can be one of the following values:

EXTR_OVERWRITE
If there is a collision, overwrite the existing variables.
EXTR_SKIP
If there is a collision, do not overwrite the existing variables.
EXTR_PREFIX_SAME
If there is a collision, the prefix of the variable name.
EXTR_PREFIX_ALL
The prefix of all variable names.
EXTR_PREFIX_INVALID
Only the prefix of variable names with invalid/numeric prefixes.
EXTR_IF_EXISTS
Only the override variable exists in the current symbol table. Otherwise, nothing is done. This is useful for defining valid variables in the list, and then extract only has those variables you have defined $ _ REQUEST arrays, for example.
EXTR_PREFIX_IF_EXISTS
Only the prefix variable name is created. If the same variable is not prefixed, it exists in the current symbol table.
EXTR_REFS
Extract Variable reference. This actually means that the value import still references the value of the variable, var_array parameter. You can use this flag, OR 'ing's extract_type, either by yourself OR in combination with any other flag.

If extract_type is not specified, this is assumed EXTR_OVERWRITE.

Prefix
Note that only the prefix extract_type is EXTR_PREFIX_SAME, EXTR_PREFIX_ALL, EXTR_PREFIX_INVALID or EXTR_PREFIX_IF_EXISTS. If the prefix result is a valid variable name, it is not imported to the symbol table. Prefix automatically disconnects from an array.


Return value
Returns some variables that are successfully imported to the symbol table.

Modify

Version description
4.3.0 EXTR_REFS added.
4.2.0 EXTR_IF_EXISTS and EXTR_PREFIX_IF_EXISTS are added.
4.0.5 this function now returns some variables. EXTR_PREFIX_INVALID is added. EXTR_PREFIX_ALL includes numeric variables and.


Instance

Example of # 1extract ()

One possible use of extract () is to import to the symbol table variable containing the associated array and return wddx_deserialize ().

<? Php

/* Suppose that $ var_array is an array returned from
Wddx_deserialize */

$ Size = "large ";
$ Var_array = array ("color" => "blue ",
"Size" => "medium ",
"Shape" => "sphere ");
Extract ($ var_array, EXTR_PREFIX_SAME, "wddx ");

Echo "$ color, $ size, $ shape, $ wddx_sizen ";

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.