How the PHP array configuration file is used

Source: Internet
Author: User
How does the PHP array configuration file work?

Some configurations can be represented as arrays (' configuration parameters ' = = ' configuration values '), for example:
Array
(
' var1 ' = ' val1 ',
' Var2 ' = ' val2 ',
' Var3 ' = ' val3 ',
);

How do these arrays represent the configuration used?
First, add a return to this array and save it as a single file:
Return array
(
' var1 ' = ' val1 ',
' Var2 ' = ' val2 ',
' Var3 ' = ' val3 ',
);
Then, require it in another file, it returns the array, and then converts the array to a variable using the Extract function.

Example:
$catid = 1;
Returns the array
$var _array = require (' Category_ '. $catid. '. php ');
Print_r ($var _array);
Convert an array into a variable
Extract ($var _array, Extr_prefix_same, "new");
The value of a realistic variable
Echo $catid;
echo $new _catid;
Echo $module;
Echo $catname;
?>
category_1.php file:
Return array
(
' catid ' = ' 10 ',
' Module ' = ' lightphp ',
' Type ' = ' 1 ',
' ModelID ' = ' 0 ',
' CatName ' = ' website introduction ',
' Description ' = ',
);
?>

-------------------------------------------------
Resources:

PHP Extract

Definition and usage
The PHP extract () 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 is used to specify how the extract () function treats conflicts when a variable already exists and the element with the same name in the array.
This function returns the number of variables that were set successfully.

Grammar
Extract (Array,extract_rules,prefix)

Example
$a = ' Original ';
$my _array = Array ("A" = "Cat", "b" = "Dog", "c" = "Horse");
Extract ($my _array);
echo "\ $a = $a; \ $b = $b; \ $c = $c ";
?>
Output:
$a = Cat;
$b = Dog;
$c = Horse

Example 2
Array key names are converted into variables and output
Suppose $var _array is an array returned by wddx_deserialize
$size = "large";
$var _array = Array ("Color" = "Blue",
"Size" = "Medium",
"Shape" = "sphere");
Extract ($var _array, Extr_prefix_same, "WDDX");
echo "$color, $size, $shape, $wddx _sizen";
?>
The example above will output:
Blue, large, sphere, medium
The $size is not overwritten because Extr_prefix_same is specified, which makes $WDDX _size be built.
If Extr_skip is specified, the $WDDX _size will not be established.
Extr_overwrite will make the value of the $size "medium",
Extr_prefix_all will create new variables $wddx _color, $WDDX _size and $wddx _shape.

Zhang Qing (mesh), Weibo: http://t.qq.com/zhangking
From "Mesh Horizon": http://blog.why100000.com
"100,000 Why" computer Learning Network: http://www.why100000.com
2013-4-2

  • Related Article

    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.