This article introduces, the PHP array as a configuration file usage, a few small examples for everyone to learn the reference. In PHP programming, it is often used in the form of arrays (' configuration parameters ' = = ' config value ') as a configuration file, for example: Array (' var1 ' = ' val1 ', ' var2 ' = ' val2 ', ' var3 ' = ' val3 ',);This article introduces the specific use of the array configuration file, for your reference. 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:
category_1.php file:
' Ten ', ' module ' = ' lightphp ', ' type ' = ' 1 ', ' modelid ' = ' 0 ', ' catname ' and ' ' website introduction ', ' Description ' = + ',);? >
The above code, using the Extract function, the following describes its usage. PHP extract defines and uses the PHP extract () function to import variables from an 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. Syntax Extract (Array,extract_rules,prefix) Example:
"Cat", "b" = "Dog", "C" and "Horse"); Extract ($my _array); echo "\ $a = $a; \ $b = $b; \ $c = $c ";? >
Output: $a = Cat; $b = Dog; $c = Horse Example 2 The array key name is converted into a variable and output:
"Blue", "size" = "medium", "shape" = "sphere"), Extract ($var _array, Extr_prefix_same, "WDDX"), echo "$color, $size , $shape, $wddx _sizen ";? >
Output: Blue, large, sphere, medium$size are not overwritten because the 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 a new variable $wddx _color, $wddx _size and $wddx _shape. |