Config_Container::toArray()

Config_Container::toArray() -- Return key/value pair array of container and its children

概要

require_once 'Config/Container.php';

array Config_Container::toArray (void)

説明

This method returns an array representation of the Config tree. The format is


<?php
$section[directive][index] = value
?>

If the container has attributes, it will use '@' as key for attributes and '#' for values. index is here because multiple directives and sections can have the same name, the toArray() method takes care of that.

返り値

array - an array representation of the Config_Container tree

注意

この関数は、スタティックにコールする ことはできません。

例 31-1Using toArray()()


<?php
$attributes = array('id' => 'db', 'language' => 'en');
     $section =& new Config_Container('section', 'main', null, $attributes);
     $section->createDirective('authentication', 'one', array('type' => 'mysql'));
     $section->createDirective('authentication', 'two', array('type' => 'oracle'));
     $section->createDirective('permission', 'group');
     var_dump($section->toArray());
?>

例 31-2Resulting array with attributes and directives with same name or not

array(1) {
  ["main"]=>
  array(3) {
    ["@"]=>
    array(2) {
      ["id"]=>
      string(2) "db"
      ["language"]=>
      string(2) "en"
    }
    ["authentication"]=>
    array(2) {
      [0]=>
      array(2) {
        ["#"]=>
        string(3) "one"
        ["@"]=>
        array(1) {
          ["type"]=>
          string(5) "mysql"
        }
      }
      [1]=>
      array(2) {
        ["#"]=>
        string(3) "two"
        ["@"]=>
        array(1) {
          ["type"]=>
          string(6) "oracle"
        }
      }
    }
    ["permission"]=>
    string(5) "group"
  }
}