本文整理汇总了PHP中RecursiveArrayIterator::getChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveArrayIterator::getChildren方法的具体用法?PHP RecursiveArrayIterator::getChildren怎么用?PHP RecursiveArrayIterator::getChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RecursiveArrayIterator
的用法示例。
在下文中一共展示了RecursiveArrayIterator::getChildren方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: traverse
function traverse(RecursiveArrayIterator $iterator)
{
while ($iterator->valid()) {
if ($iterator->hasChildren()) {
printf("HasChild: %s\n", $iterator->key());
traverse($iterator->getChildren());
} else {
printf("%s => %s\n", $iterator->key(), $iterator->current());
}
$iterator->next();
}
}
示例2: walkArray
/**
* Walks through array
* @param $array
* @param $callback callable function($path, $value)
*/
public static function walkArray($array, $callback, $iterator = null, $prefix = '')
{
if (is_null($iterator)) {
$iterator = new \RecursiveArrayIterator($array);
}
while ($iterator->valid()) {
if ($iterator->hasChildren()) {
self::walkArray(null, $callback, $iterator->getChildren(), $prefix . '.' . $iterator->key());
} else {
call_user_func($callback, ltrim($prefix . '.' . $iterator->key(), '.'), $iterator->current());
}
$iterator->next();
}
}
示例3: parseJson
private function parseJson(\RecursiveArrayIterator $json, array $data, $level)
{
foreach ($json as $k => $j) {
if (!isset($this->path[$level])) {
return $data;
}
if ($k !== $this->path[$level] && $this->path[$level] !== '*') {
continue;
}
if ($k === end($this->path)) {
if (is_array($j)) {
$data = array_merge($data, $j);
} else {
$data[] = $j;
}
}
if ($json->hasChildren()) {
$data = $this->parseJson($json->getChildren(), $data, $level + 1);
}
}
return $data;
}
示例4: getChildren
function getChildren()
{
echo __METHOD__ . "\n";
return parent::getChildren();
}
示例5: fetchCategoriesWithProducts
/**
* @param RecursiveArrayIterator $iterator
*/
public function fetchCategoriesWithProducts(RecursiveArrayIterator $iterator)
{
while ($iterator->valid()) {
if ($iterator->hasChildren()) {
$this->fetchCategoriesWithProducts($iterator->getChildren());
} else {
if ($iterator->key() == 'countProducts' && $iterator->current() != '0') {
$this->_categoryWithProducts[$iterator->offsetGet('id')] = array('name' => $iterator->offsetGet('name'), 'full_path' => $iterator->offsetGet('full_path'), 'countProduct' => $iterator->offsetGet('countProducts'));
}
/*$this->_categoryWithProducts[$iterator->offsetGet('id')] =
$iterator->offsetGet('countProducts');*/
}
$iterator->next();
}
}
示例6: findNode
/**
* Find and return the bottom node in the given tree
* @param \RecursiveArrayIterator $iterator
* @param array $tree
* @return mixed Array with 0: iterator, 1: value (reference)
*/
protected function findNode(\RecursiveArrayIterator $iterator, $tree = [])
{
$find_key = array_shift($tree);
foreach ($iterator as $key => &$value) {
if ($key !== $find_key) {
continue;
}
# $tree isn't null yet, meaning we still have to travel down
# nodes in order to get to the last one... inception
if (isset($tree[0])) {
return $this->findNode($iterator->getChildren(), $tree);
}
# Return a reference to this current node - it's needed later. More details
# are in the findValue() function. Yeah, it's kinda hackey
return [$iterator, &$value];
}
return null;
}
示例7: getChildren
public function getChildren()
{
echo "MyArrIter::getChildren\n";
return parent::getChildren();
}
示例8: getChildren
function getChildren()
{
echo __METHOD__ . "()\n";
self::fail(2, __METHOD__);
return parent::getChildren();
}
示例9: array
function traverse_structure($ids)
{
$return_ids = array();
$iterator = new RecursiveArrayIterator($ids);
while ($iterator->valid()) {
if ($iterator->hasChildren()) {
$return_ids = array_merge($return_ids, $this->traverse_structure($iterator->getChildren()));
} else {
if ($iterator->key() == 'int') {
$return_ids = array_merge($return_ids, array($iterator->current()));
}
}
$iterator->next();
}
return $return_ids;
}
示例10: walkInputArray
/**
* Walks through input array
*
* @param $array
* @param $callback callable function($path, $value)
* @param null $iterator
* @param string $prefix
*/
private function walkInputArray($array, $callback, $iterator = null, $prefix = '')
{
if (!$iterator) {
$iterator = new \RecursiveArrayIterator($array);
}
while ($iterator->valid()) {
$key = $iterator->key();
if ($iterator->hasChildren()) {
$this->walkInputArray(null, $callback, $iterator->getChildren(), $prefix . '.' . $key);
} else {
call_user_func($callback, ltrim($prefix . '.' . $key, '.'), $iterator->current());
}
$iterator->next();
}
}
示例11: highlightElement
private function highlightElement($indexArray, $menuArray = null, $nr = 0)
{
//index to get
$i = $indexArray[$nr];
//if menu is null take menuArray
if ($menuArray == null) {
$menuArray = $this->menuArray;
}
//create itterator
$iter = new RecursiveArrayIterator($menuArray);
//move to current index
$iter->seek($i);
//move down until we have found the element - then set the css-class for that element
if (is_array($iter->current())) {
$this->highlightElement($indexArray, $iter->getChildren(), $nr + 1);
} else {
$iter->current()->cssClass = $this->cssClass;
}
}
示例12: reducer
/**
* Helper to `names`, which recursively traverses the iterator appending
* new keys onto the base-so-far.
*
* @param \RecursiveArrayIterator $it
* @param string $base
* @param array $names
*/
private function reducer(\RecursiveArrayIterator $it, $base, &$names)
{
while ($it->valid()) {
$sub_base = sprintf('%s[%s]', $base, $it->key());
if ($it->hasChildren()) {
$this->reducer($it->getChildren(), $sub_base);
} else {
$names[] = $sub_base;
}
$it->next();
}
}
示例13: array
<?php
class Persona
{
public $nome = 'Mario';
public $cognome = 'Rossi';
public $telefono = array('cellulare' => '114499', 'ufficio' => '224433');
public $socials = array('twitter' => 'rossi', 'facebook' => 'http://www.facebook.com/rossi');
}
$iterator = new RecursiveArrayIterator(new Persona());
foreach ($iterator as $index => $value) {
if ($iterator->hasChildren()) {
foreach ($iterator->getChildren() as $key => $child) {
echo $key . ': ' . $child, PHP_EOL;
}
} else {
echo $index . ': ' . $value, PHP_EOL;
}
}
示例14: encode_iterator
protected static function encode_iterator(RecursiveArrayIterator $iterator, $options, $depth)
{
$json = array();
while ($iterator->valid()) {
$key = $iterator->key();
$value = $iterator->current();
if ($value instanceof JSExpression) {
var_dump($value);
$json[$key] = $value->json_encode($options);
} else {
if ($iterator->hasChildren()) {
if (!($depth > 0)) {
throw new Exception("Maximum depth reached");
}
$json[$key] = static::encode_iterator($iterator->getChildren(), $options, $depth - 1);
} else {
$json[$key] = static::encode_value($iterator->current(), $options);
}
}
$iterator->next();
}
var_dump($json);
if (self::is_numeric_array($json)) {
return '[' . implode(",", $json) . ']';
} else {
foreach (array_keys($json) as $key) {
$json[$key] = static::encode_key($key, $options) . ':' . $json[$key];
}
return '{' . implode(",", $json) . '}';
}
}