The function of the PHP extract function is to import 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. One trick with the extract function is to make the field variable and easy to invoke.
$info = $this->db->get_one (array (' ID ' => $specialid, ' disabled ' =>0));
Imports the field corresponding to the current topic ID as a variable into the current symbol table
Extract ($info);
This example $info the result from the database, in the form of an array as a variable, the key name is the field name, the value is the field value, use the Extract function as the variable name, the field value as the variable value.
such as Array (' name ' => ' Zhangsan ', ' sex ' => ' man ', ' id ' =>3232);
Then extract ($array), you can directly use $name, $sex, $id.
Look again
<?php
$size = "Old Size"; Note the value of the last size variable.
$a = Array (
"Color" => "red",
"Size" => "XXL",
"Price" => "53");
Extract ($a);
echo "color = $color <br/>";
echo "size = $size <br/>";
echo "Price = $price <br/>";
?>
The results are:
color = Red
Size = XXL
Price = 53
The above example finds that the value of $size is XXL instead of the previous "old size", which means that the original variable is overwritten by default when the key in the array conflicts with an existing variable.
Example
Form.html
<form action= "action.php" method= "POST" >
<input type= "text" name= "username" >
<input type= "password" name= "password" >
<input type= "Submit" >
Use the Extract () function in action.php to unlock the $_post global data:
action.php
<?php
Extract ($_post);
Equivalent to $username = $_post[' username '];
$password = $_post[' password '];
?>
Is it convenient?
Analysis of the function of extract
Addslashes--referencing strings using backslashes
Extract (Addslashes ($_post)); --Handling post forms
Take the variable name from the client <form method= "POST" ...> form.
Extract (Addslashes ($_get)); --Handling Get forms
The
takes the client <form method= "get" ...> the name of the variable in the form.