当前位置:网站首页>PHP extract() function
PHP extract() function
2022-06-24 05:11:00 【User 1448800】
example
Will be the key value "Cat"、"Dog" and "Horse" Assign a value to a variable $a、$b and $c:
<?php
$a = "Original";
$my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse");
extract($my_array);
echo "\$a = $a; \$b = $b; \$c = $c";
?>Definition and Usage
extract() Function to import variables from an array into the current symbol table .
This function uses the array key name as the variable name , Use array key value as variable value . For each element in the array , A corresponding variable will be created in the current symbol table .
The second parameter type Used to specify when a variable already exists , When there are elements with the same name in the array ,extract() How functions deal with such conflicts .
This function returns the number of variables successfully imported into the symbol table .
grammar
extract(array,extract_rules,prefix)
Parameters | describe |
|---|---|
array | It's necessary . Specify the array to use . |
extract_rules | Optional .extract() The function checks that each key name is a valid variable name , It also checks whether it conflicts with the existing variable names in the symbol table . Handling illegal and conflicting key names will be determined by this parameter . Possible value :EXTR_OVERWRITE - Default . If there is a conflict , Overwrite existing variables .EXTR_SKIP - If there is a conflict , Do not overwrite existing variables .EXTR_PREFIX_SAME - If there is a conflict , Prefix variable names prefix.EXTR_PREFIX_ALL - Prefix all variable names prefix.EXTR_PREFIX_INVALID - Prefix only illegal or numeric variable names prefix.EXTR_IF_EXISTS - Only when a variable with the same name already exists in the current symbol table , Override their values . Nothing else .EXTR_PREFIX_IF_EXISTS - Only when a variable with the same name already exists in the current symbol table , Create variable names with prefixes attached , Nothing else .EXTR_REFS - Extract variables as references . The imported variable still references the value of the array parameter . |
prefix | Optional . Please note that prefix Only in extract_type The value of is EXTR_PREFIX_SAME,EXTR_PREFIX_ALL,EXTR_PREFIX_INVALID or EXTR_PREFIX_IF_EXISTS The need when . If the result after prefixing is not a legal variable name , Will not be imported into the symbol table . An underscore is automatically added between the prefix and the array key name . |
- EXTR_OVERWRITE - Default . If there is a conflict , Overwrite existing variables .
- EXTR_SKIP - If there is a conflict , Do not overwrite existing variables .
- EXTR_PREFIX_SAME - If there is a conflict , Prefix variable names prefix.
- EXTR_PREFIX_ALL - Prefix all variable names prefix.
- EXTR_PREFIX_INVALID - Prefix only illegal or numeric variable names prefix.
- EXTR_IF_EXISTS - Only when a variable with the same name already exists in the current symbol table , Override their values . Nothing else .
- EXTR_PREFIX_IF_EXISTS - Only when a variable with the same name already exists in the current symbol table , Create variable names with prefixes attached , Nothing else .
- EXTR_REFS - Extract variables as references . The imported variable still references the value of the array parameter .
prefix Optional . Please note that prefix Only in extract_type The value of is EXTR_PREFIX_SAME,EXTR_PREFIX_ALL,EXTR_PREFIX_INVALID or EXTR_PREFIX_IF_EXISTS The need when . If the result after prefixing is not a legal variable name , Will not be imported into the symbol table . An underscore is automatically added between the prefix and the array key name .
Technical details
Return value : | Returns the number of variables successfully imported into the symbol table . |
|---|---|
PHP edition : | 4+ |
Update log : | extract_rules Value EXTR_REFS Is in PHP 4.3 In the new .extract_rules Value EXTR_IF_EXISTS and EXTR_PREFIX_IF_EXISTS Is in PHP 4.2 In the new . since PHP 4.0.5 rise , This function returns the number of variables successfully imported into the symbol table .extract_rules Value EXTR_PREFIX_INVALID Is in PHP 4.0.5 In the new . since PHP 4.0.5 rise ,extract_rules Value EXTR_PREFIX_ALL It also contains numeric variables . |
More instances
Example 1
Use all parameters :
<?php
$a = "Original";
$my_array = array("a" => "Cat", "b" => "Dog", "c" => "Horse");
extract($my_array, EXTR_PREFIX_SAME, "dup");
echo "\$a = $a; \$b = $b; \$c = $c; \$dup_a = $dup_a";
?>边栏推荐
- What are the functions and advantages of the Internet of things cloud platform?
- How to clone virtual machines on vspere client
- Precautions for online education and training industry filing
- How does the mobile phone remotely connect to the ECS? What should be paid attention to during the operation
- The most complete regular expression summary in the whole network, so that you can get twice the result with half the effort. Collect it quickly
- How to set easycvr recording plan batch and single channel settings?
- 问题:sql创建存储过程
- TDP members have made their debut!
- What is the difference between a traditional data center and a cloud computing data center?
- What is an evpn switch?
猜你喜欢

『渗透基础』Cobalt Strike基础使用入门_Cobalt Strike联动msfconsole

解析后人类时代类人机器人的优越性

Leetcode (question 1) - sum of two numbers

CTF learning notes 17:iwesec file upload vulnerability-02 file name filtering bypass

Analyzing the superiority of humanoid robot in the post human era

少儿编程课程改革后的培养方式

Analysis on the subjective enthusiasm of post-90s makers' Education

Loss and optimization of linear regression, machine learning to predict house prices

CTF learning notes 18:iwesec file upload vulnerability-03-content-type filtering bypass

Intensive learning and application of "glory of the king" to complete the application of 7 real worlds other than human players
随机推荐
解析后人类时代类人机器人的优越性
Introduction to ebpf
Shuttle global levitation button
Inventory of common tools used by dry goods | data journalists
014_ TimePicker time selector
Performance comparison of JS loop traversal methods: for/while/for in/for/map/foreach/every
The personal information protection law was formally reviewed and passed. What issues should enterprises pay attention to?
The function of nearby people in the applet is realized, and the cloud development database is used to realize nearby people and friends within a distance of the neighborhood
Bi-sql distinct
Shutter - how to copy certain elements from a map to a new map in dart/shutter?
[jest] summary of the use of automated test jest
Precautions for online education and training industry filing
Spirit breath development log (11)
How to control CDN traffic gracefully in cloud development?
Why domain name should be resolved? What is the domain name registration query
What is stored in the domain name server? How does the domain name server provide services?
Open source and SaaS, how to choose software?
Where to buy domain name space? Can the domain name be repeated?
3 minutes to understand JSON schema
让孩子们学习Steam 教育的应用精髓