本文整理汇总了PHP中RecursiveArrayIterator类的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveArrayIterator类的具体用法?PHP RecursiveArrayIterator怎么用?PHP RecursiveArrayIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RecursiveArrayIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: recursiveScan
private function recursiveScan(\RecursiveArrayIterator $iterator)
{
while ($iterator->valid()) {
$this->checkIblockData($iterator);
if ($iterator->hasChildren()) {
$this->recursiveScan($iterator->getChildren());
} else {
$this->checkIblockData($iterator);
}
$iterator->next();
}
}
示例2: search
/**
* Searches value inside a multidimensional array, returning its index
*
* Original function by "giulio provasi" (link below)
*
* @param mixed|array $haystack
* The haystack to search
*
* @param mixed $needle
* The needle we are looking for
*
* @param mixed|optional $index
* Allow to define a specific index where the data will be searched
*
* @return integer|string
* If given needle can be found in given haystack, its index will
* be returned. Otherwise, -1 will
*
* @see http://www.php.net/manual/en/function.array-search.php#97645
*/
public static function search($haystack, $needle, $index = NULL)
{
if (is_null($haystack)) {
return -1;
}
$arrayIterator = new \RecursiveArrayIterator($haystack);
$iterator = new \RecursiveIteratorIterator($arrayIterator);
while ($iterator->valid()) {
if ((isset($index) and $iterator->key() == $index or !isset($index)) and $iterator->current() == $needle) {
return $arrayIterator->key();
}
$iterator->next();
}
return -1;
}
示例3: find
/**
* Find a named route in a given array of routes.
*
* @param string $name
* @param array $routes
* @return array
*/
public static function find($name, $routes)
{
if (array_key_exists($name, static::$names)) {
return static::$names[$name];
}
$arrayIterator = new \RecursiveArrayIterator($routes);
$recursiveIterator = new \RecursiveIteratorIterator($arrayIterator);
// Since routes can be nested deep within sub-directories, we need to recursively
// iterate through each directory and gather all of the routes.
foreach ($recursiveIterator as $iterator) {
$route = $recursiveIterator->getSubIterator();
if (isset($route['name']) and $route['name'] == $name) {
return static::$names[$name] = array($arrayIterator->key() => iterator_to_array($route));
}
}
}
示例4: 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();
}
}
示例5: 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();
}
}
示例6: rarray_search
/**
*
* Search for needle in a recursive array
* @author http://www.php.net/manual/en/function.array-search.php#97645
*
* @param $haystack
* @param $needle
* @param $index
*/
function rarray_search($needle, $haystack, $index = null)
{
$aIt = new RecursiveArrayIterator($haystack);
$it = new RecursiveIteratorIterator($aIt);
// Tar bort ".www" om det finns för bättre jämföring
$needle = preg_replace('/\bwww./', '', $needle);
while($it->valid())
{
// Tar bort ".www" om det finns för bättre jämföring
$current = preg_replace('/\bwww./', '', $it->current());
if (((isset($index) AND ($it->key() == $index)) OR (!isset($index))) AND ($current == $needle))
{
return $aIt->key();
}
$it->next();
}
return FALSE;
}
示例7: buildResources
/**
* @param \RecursiveArrayIterator $iterator
* @return mixed
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
*/
protected function buildResources(\RecursiveArrayIterator $iterator)
{
if (count($this->mapping) == 0) {
throw new HttpException(Codes::HTTP_BAD_REQUEST, 'Unable to generate CMMI Data, no mapping is known');
}
$this->resource = new Resource(new Link($this->request->getUri(), 'self'));
if ($iterator->hasChildren()) {
while ($iterator->valid()) {
$childItem = $iterator->current();
$this->addResource(new \RecursiveArrayIterator($childItem));
$iterator->next();
}
} else {
$this->addResource($iterator);
}
return $this->resource;
}
示例8: searchRecursive
/**
* Find a value also in nested arrays/objects
*
* @param mixed $needle The value to search for
*
* @return string The key of that value
*
* @since 1.0.0
*/
public function searchRecursive($needle)
{
$aIt = new RecursiveArrayIterator($this);
$it = new RecursiveIteratorIterator($aIt);
while ($it->valid()) {
if ($it->current() == $needle) {
return $aIt->key();
}
$it->next();
}
return false;
}
示例9: str_split
<div>
<label for="y">Input int. for y axis</label>
<input type="text" name="y">
</div>
<div>
<label for="directions">Input string for directions</label>
<input type="text" name="directions">
</div>
<input type="submit" name="submit" value="Go!">
</form>
<?php
$move_data = str_split($directions);
//var_dump($move_data);
$recusive = new RecursiveArrayIterator($move_data);
$reverse = 0;
while ($recusive->valid()) {
$direction = $recusive->current();
if ($direction == '~') {
$reverse++;
$recusive->next();
} else {
if ($reverse % 2) {
if ($direction == '>') {
$_x++;
} elseif ($direction == '<') {
$_x--;
} elseif ($direction == 'v') {
$_y++;
} elseif ($direction == '^') {
示例10: 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();
}
}
示例11: 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;
}
示例12: array_get
function array_get($array, $searched, $index)
{
$aIt = new RecursiveArrayIterator($array);
$it = new RecursiveIteratorIterator($aIt);
while ($it->valid()) {
if ((isset($index) and $it->key() == $index or !isset($index)) and $it->current() == $searched) {
$c = $aIt->current();
return $c;
// return $c[$key];
}
$it->next();
}
return FALSE;
}
示例13: __construct
/**
* @param array $array
*/
public function __construct($array)
{
if (is_object($array)) {
$array = $array->toArray();
}
parent::__construct($array);
}
示例14: __construct
public function __construct(\ResourceBundle $bundle)
{
$storage = array();
foreach ($bundle as $key => $value) {
$storage[$key] = $value instanceof \ResourceBundle ? new self($value) : $value;
}
parent::__construct($storage);
}
示例15: valid
function valid()
{
if (!parent::valid()) {
echo __METHOD__ . " = false\n";
return false;
} else {
return true;
}
}