コード例 #1
0
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
0
ファイル: Arrays.php プロジェクト: myurasov/mym-utils
 /**
  * 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
0
ファイル: CMMIDataHelper.php プロジェクト: pitoukhmer/protalk
 /**
  * @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;
 }
コード例 #4
0
 public function getChildren()
 {
     $section = parent::current();
     return new self($section['topics'], 0, $this->path . '/' . $this->key());
 }
コード例 #5
0
 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;
 }
コード例 #6
0
ファイル: FileContents.php プロジェクト: helgi/Pyrus
 function current()
 {
     $x = parent::current();
     return new FileTag($x, $this->dir, $this->_packagefile);
 }
コード例 #7
0
ファイル: points-solution.php プロジェクト: jokuf/solutions
    </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 == '^') {
                $_y--;
            }
        } else {
 /**
  * @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();
     }
 }
コード例 #9
0
 function getChildren()
 {
     return new SimpleXpathStructure(parent::current());
 }
コード例 #10
0
 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;
 }
コード例 #11
0
ファイル: gldbmysql.php プロジェクト: shavez00/groceryList
 public function getColumns($table = NULL)
 {
     if ($table === NULL) {
         throw new \Exception("Please input a table name. - glDbMysql.php - line 89");
     }
     if (!in_array($table, $this->getTables())) {
         throw new \Exception("The table you're trying to query does not exist - glDbMysql.php - line 91");
     }
     $dbh = $this->getDbh();
     $stmt = $dbh->prepare("DESCRIBE " . $table);
     $success = $stmt->execute();
     $columnNames = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $iterator = new \RecursiveArrayIterator($columnNames);
     $fields = array();
     if ($success !== FALSE) {
         while ($iterator->valid()) {
             if ($iterator->hasChildren()) {
                 $childIterator = new \RecursiveArrayIterator($iterator->current());
                 while ($childIterator->valid()) {
                     if ($childIterator->key() == "Field") {
                         array_push($fields, $childIterator->current());
                     }
                     $childIterator->next();
                 }
             }
             $iterator->next();
         }
         return $fields;
     }
     $error = array('query' => "DESCRIBE " . $table, 'errorInfo' => $this->prepareErrorInfo($dbh->errorInfo()));
     $errorInfo = json_encode($error);
     throw new MysqlException($errorInfo);
 }
コード例 #12
0
 /**
  * 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();
     }
 }
コード例 #13
0
 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;
     }
 }
コード例 #14
0
<?php

/*** an array of animal ***/
$animals = array(array('type' => 'dog', 'name' => 'butch', 'sex' => 'm', 'breed' => 'boxer'), array('type' => 'dog', 'name' => 'fido', 'sex' => 'm', 'breed' => 'doberman'), array('type' => 'dog', 'name' => 'girly', 'sex' => 'f', 'breed' => 'poodle'), array('type' => 'cat', 'name' => 'tiddles', 'sex' => 'm', 'breed' => 'ragdoll'), array('type' => 'cat', 'name' => 'tiddles', 'sex' => 'f', 'breed' => 'manx'), array('type' => 'cat', 'name' => 'tiddles', 'sex' => 'm', 'breed' => 'maine coon'), array('type' => 'horse', 'name' => 'ed', 'sex' => 'm', 'breed' => 'clydesdale'), array('type' => 'perl_coder', 'name' => 'shadda', 'sex' => 'none', 'breed' => 'mongrel'), array('type' => 'duck', 'name' => 'galapogus', 'sex' => 'm', 'breed' => 'pekin'));
/*** create a new recursive array iterator ***/
$iterator = new RecursiveArrayIterator(new ArrayObject($animals));
/*** traverse the $iterator object ***/
while ($iterator->valid()) {
    echo $iterator->key() . ' -- ' . $iterator->current() . '<br/>';
    $iterator->next();
}
コード例 #15
0
ファイル: classFeed.php プロジェクト: rjon76/netspotapp
    public function BuildFeed()
    {
        $xml = '<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>

';
        // build channel title
        for ($iterator = $this->FeedTitle->getIterator(); $iterator->valid(); $iterator->next()) {
            $xml .= '<' . $iterator->key() . '>' . $iterator->current() . '</' . $iterator->key() . '>' . "\n";
            if ('title' == $iterator->key()) {
                $xml .= $this->BuildFeedAtom();
            }
        }
        // build channel items
        $iterator = new RecursiveArrayIterator($this->FeedItems);
        while ($iterator->hasChildren()) {
            $xml .= '<item>' . "\n";
            for ($sub_iterator = $iterator->current()->getIterator(); $sub_iterator->valid(); $sub_iterator->next()) {
                if ('guid' == $sub_iterator->key()) {
                    $xml .= '<' . $sub_iterator->key() . ' isPermaLink ="' . ($sub_iterator->offsetGet('isPermaLink') ? 'true' : 'false') . '">' . $sub_iterator->current() . '</' . $sub_iterator->key() . '>' . "\n";
                } elseif ('isPermaLink' != $sub_iterator->key()) {
                    $xml .= '<' . $sub_iterator->key() . '>' . $sub_iterator->current() . '</' . $sub_iterator->key() . '>' . "\n";
                }
            }
            $xml .= '</item>' . "\n";
            $iterator->next();
        }
        $xml .= '</channel>
</rss>';
        return $xml;
    }
コード例 #16
-1
 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) . '}';
     }
 }