The Extract function in PHP

Source: Internet
Author: User
Tags date array copy numeric variables variable tostring valid
The extract function is used to decompose a number into variables for direct use, and the following is the interpretation of the extract: The PHP () function imports variables from the array into the current symbol table. For each element in the array, the key name is used for the variable name, and the key value is used for the variable value. The second parameter type specifies how the extract () function treats such a conflict when a variable already exists and an element with the same name is in the array. This function returns the number of variables that were successfully set.   The following table is a parameter description:   syntax extract (array,extract_rules,prefix) parameter description array required. Specify the input to use. Extract_rules Optional. The extract () function checks whether each key name is a valid variable name and also checks to see if the variable name in the symbol table conflicts.   Processing of key names for illegal, numeric, and conflicting keys is determined according to this parameter. Can be one of the following values:   Possible values:   Extr_overwrite-Default. If there is a conflict, overwrite the existing variable. Extr_skip-If there is a conflict, do not overwrite existing variables. (ignores elements of the same name in the array) Extr_prefix_same-if there is a conflict, prefix the variable name PREFIX. Since PHP 4.0.5, this also includes processing of digital indexes. Extr_prefix_all-Prefix all variable names PREFIX (third argument). Extr_prefix_invalid-prefix PREFIX only for illegal or numeric variable names. This tag is a new addition to PHP 4.0.5. Extr_if_exists-overwrites their values only if there is already a variable of the same name in the current symbol table. Nothing else is to be dealt with. You can use an instance where you have defined a set of valid variables and then extract the values from an array such as $_request to overwrite these variables. This tag is a new addition to PHP 4.2.0. Extr_prefix_if_exists-the variable name with the prefix appended is established only if there is already a variable with the same name in the current symbol table. This tag is a new addition to PHP 4.2.0. Extr_refs-Extracts a variable as a reference. This is a powerful indication that the imported variable still references the value of the Var_array parameter. This flag can be used alone or in conjunction with any other flag in Extract_type. This tag is a new addition to PHP 4.3.0. Prefix optional. Please note that prefix only in extract_tThe value of the ype is required when extr_prefix_same,extr_prefix_all,extr_prefix_invalid or extr_prefix_if_exists. If the result appended with a prefix is not a valid variable name, it will not be imported into the symbol table. An underscore is automatically added between the   prefix and array key names.       This is good for getting a row of data from the database, let's take a look at the following example   copy code <?php  $DB = mysql_connect (' localhost ', ' root ', ' Ctrip07185419 ') or die (' can not connect to MySQL '); mysql_select_db (' MovieSite ', $db) or Die (Mysql_error ($db)); mysql_query (' Set names GBK ', $db); if (Isset ($_get[' action ')) && $_get[' action '] = = ' edit ')   {    $query = ' SELECT movie_name,movie_t Ype,movie_year,movie_leadactor,movie_director from movie WHERE movie_id= '. $_get[' id '];    //echo $query;     $result = mysql_query ($query, $db) or Die (Mysql_error ($db));     Extract (Mysql_fetch_assoc ($result)); else {    $movie _name= ';     $movie _type=0     $movie _year=date (' Y ');     $MO vie_leadactor=0;     $movie _director=0; }?>

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.