PHPextract () function usage php array splitting

Source: Internet
Author: User
PHPextract () function usage php array splitting

In action. php, you only need to use the extract () function to unbind the $ _ POST global data: action. php

  1. Extract ($ _ POST );
  2. // Equivalent to $ username = $ _ POST ['username'];
  3. // $ Password = $ _ POST ['password'];
  4. ?>

Explanation in the php manual:

Extract (PHP 4, PHP 5)

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

Int extract (array $ var_array [, int $ extract_type [, string $ prefix])

This function is used to import variables from the array to the current symbol table. The array var_array is used as the parameter and the key name is used as the variable name, and the value is used as the variable value. Each key/value pair will create a variable in the current symbol table and be affected by the extract_type and prefix parameters.

Note: This function returns the number of extracted variables from version 4.0.5.

Note: EXTR_IF_EXISTS and EXTR_PREFIX_IF_EXISTS are introduced in version 4.2.0.

Note: EXTR_REFS is introduced in version 4.3.0.

Extract () checks each key name to see if it can be used as a valid variable name. it also checks for conflicts with existing variable names in the symbol table. The method for dealing with illegal/numbers and conflicting key names is determined by the extract_type parameter. It can be one of the following values:

  1. /* Assume that $ var_array is the array returned by wddx_deserialize */
  2. $ Size = "large ";
  3. $ Var_array = array ("color" => "blue ",
  4. "Size" => "medium ",
  5. "Shape" => "sphere ");
  6. Extract ($ var_array, EXTR_PREFIX_SAME, "wddx ");
  7. Echo "$ color, $ size, $ shape, $ wddx_size \ n ";
  8. ?>

Output in the previous example: blue, large, sphere, medium

$ Size is not overwritten. because EXTR_PREFIX_SAME is specified, $ wddx_size is created. If EXTR_SKIP is specified, $ wddx_size is not created. EXTR_OVERWRITE sets the value of $ size to "medium", and EXTR_PREFIX_ALL creates a new variable $ wddx_color, $ wddx_size, and $ wddx_shape.

The associated array must be used. the array of the numeric index will not produce results unless EXTR_PREFIX_ALL or EXTR_PREFIX_INVALID is used.

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.