本文整理匯總了PHP中Spyc::flatten方法的典型用法代碼示例。如果您正苦於以下問題:PHP Spyc::flatten方法的具體用法?PHP Spyc::flatten怎麽用?PHP Spyc::flatten使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Spyc
的用法示例。
在下文中一共展示了Spyc::flatten方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addArray
function addArray($array, $indent)
{
$key = key($array);
if (!isset($array[$key])) {
return false;
}
if ($array[$key] === array()) {
$array[$key] = '';
}
$value = $array[$key];
// Unfolding inner array tree as defined in $this->_arrpath.
//$_arr = $this->result; $_tree[0] = $_arr; $i = 1;
$tempPath = Spyc::flatten($this->path);
eval('$_arr = $this->result' . $tempPath . ';');
if ($this->_containsGroupAlias) {
do {
if (!isset($this->SavedGroups[$this->_containsGroupAlias])) {
echo "Bad group name: {$this->_containsGroupAlias}.";
break;
}
$groupPath = $this->SavedGroups[$this->_containsGroupAlias];
eval('$value = $this->result' . Spyc::flatten($groupPath) . ';');
} while (false);
$this->_containsGroupAlias = false;
}
// Adding string or numeric key to the innermost level or $this->arr.
if ($key) {
$_arr[$key] = $value;
} else {
if (!is_array($_arr)) {
$_arr = array($value);
$key = 0;
} else {
$_arr[] = $value;
end($_arr);
$key = key($_arr);
}
}
$this->path[$indent] = $key;
eval('$this->result' . $tempPath . ' = $_arr;');
if ($this->_containsGroupAnchor) {
$this->SavedGroups[$this->_containsGroupAnchor] = $this->path;
$this->_containsGroupAnchor = false;
}
}
示例2: addArray
private function addArray($array, $indent)
{
if (count($array) > 1) {
return $this->addArrayInline($array, $indent);
}
$key = key($array);
if (!isset($array[$key])) {
return false;
}
$value = $array[$key];
$tempPath = Spyc::flatten($this->path);
// Unfolding inner array tree.
$_arr = $this->result;
foreach ($this->path as $k) {
$_arr = $_arr[$k];
}
if ($this->_containsGroupAlias) {
do {
if (!isset($this->SavedGroups[$this->_containsGroupAlias])) {
echo "Bad group name: {$this->_containsGroupAlias}.";
break;
}
$groupPath = $this->SavedGroups[$this->_containsGroupAlias];
$value = $this->result;
foreach ($groupPath as $k) {
$value = $value[$k];
}
} while (false);
$this->_containsGroupAlias = false;
}
// Adding string or numeric key to the innermost level or $this->arr.
if ($key) {
$_arr[$key] = $value;
} else {
if (!is_array($_arr)) {
$_arr = array($value);
$key = 0;
} else {
$_arr[] = $value;
end($_arr);
$key = key($_arr);
}
}
$this->path[$indent] = $key;
eval('$this->result' . $tempPath . ' = $_arr;');
if ($this->_containsGroupAnchor) {
$this->SavedGroups[$this->_containsGroupAnchor] = $this->path;
$this->_containsGroupAnchor = false;
}
}