PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




PHP Array extract() Function


Tutorials »Php »

Topic

What is extract() Function?



Explanation

The "extract()" function import variables into the current symbol table from an array. This function uses array keys as variable names, values as variable values. For each element it will create a variable in the current symbol table

Syntax:
    extract(array,extract_rules,prefix)

In the above syntax "array" is the array from which the variables are imported to the current symbol table.

The following is the description of the Extract_rules parameters.

Parameter Description
EXTR_OVERWRITE If there is a collision, overwrite the existing variable.
EXTR_SKIP If there is a collision, don't overwrite the existing variable.
EXTR_PREFIX_SAME If there is a collision, prefix the variable name with prefix.
EXTR_PREFIX_ALL Prefix all variable names with prefix.
EXTR_PREFIX_INVALID Only invalid or numeric variable names will be given a prefix./td>
EXTR_IF_EXISTS Only overwrite existing variables in the current symbol table, otherwise do nothing
EXTR_PREFIX_IF_EXISTS Only add prefix to variables if the same variable exists in the current symbol table.
EXTR_REFS Extracts variables as references. The imported variables are still referencing the values of the array parameter.

The "prefix" parameter is seperated by an underscore, both "extract rules", "prefix" are optional parameters.

Example:
    <?php
    $size = "large";
    $var_array = array("color" => "blue",
                   "size"  => "medium",
                   "shape" => "sphere");
    extract($var_array, EXTR_PREFIX_SAME, "dup");

    echo "$color, $size, $shape, $dup_size\n";
    ?>
Result:
    blue, large, sphere, medium

In the above example there is a collision for the variable "$size" so using the extracting rule "EXTR_PREFIX_SAME", the variable $size value that is "large" is added for size and using the prefix "dup" with size, the value "medium" is displayed.





A Note

Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial. Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.

Other Links

web hosting