当前位置: 首页>>代码示例>>PHP>>正文


PHP RecursiveArrayIterator::hasChildren方法代码示例

本文整理汇总了PHP中RecursiveArrayIterator::hasChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveArrayIterator::hasChildren方法的具体用法?PHP RecursiveArrayIterator::hasChildren怎么用?PHP RecursiveArrayIterator::hasChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RecursiveArrayIterator的用法示例。


在下文中一共展示了RecursiveArrayIterator::hasChildren方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getColumns

 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);
 }
开发者ID:shavez00,项目名称:groceryList,代码行数:33,代码来源:gldbmysql.php

示例2: 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();
    }
}
开发者ID:Eldahar,项目名称:PHP_Library,代码行数:12,代码来源:RecursiveArrayIterator1.php

示例3: 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();
     }
 }
开发者ID:myurasov,项目名称:mym-utils,代码行数:19,代码来源:Arrays.php

示例4: 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;
 }
开发者ID:pitoukhmer,项目名称:protalk,代码行数:22,代码来源:CMMIDataHelper.php

示例5: _parseData

 /**
  * Parse the upload data out of $_FILES.
  *
  * @access protected
  * @return void
  */
 protected function _parseData()
 {
     $data = array();
     // Form uploading
     if ($_FILES) {
         // via CakePHP
         if (isset($_FILES['data'])) {
             foreach ($_FILES['data'] as $key => $file) {
                 $count = count($file);
                 // Add model index if it doesn't exist
                 $iterator = new RecursiveArrayIterator($file);
                 if ($iterator->hasChildren() === false) {
                     $file = array('Fake' => $file);
                 }
                 foreach ($file as $model => $fields) {
                     foreach ($fields as $field => $value) {
                         if ($count > 1) {
                             $data[$model . '.' . $field][$key] = $value;
                         } else {
                             $data[$field][$key] = $value;
                         }
                     }
                 }
             }
             // via normal form or AJAX iframe
         } else {
             $data = $_FILES;
         }
         // AJAX uploading
     } else {
         if (isset($_GET[$this->ajaxField])) {
             $name = $_GET[$this->ajaxField];
             $mime = self::mimeType($name);
             if ($mime) {
                 $input = fopen("php://input", "r");
                 $temp = tmpfile();
                 $data[$this->ajaxField] = array('name' => $name, 'type' => $mime, 'stream' => true, 'tmp_name' => $temp, 'error' => 0, 'size' => stream_copy_to_stream($input, $temp));
                 fclose($input);
             }
         }
     }
     $this->_data = $data;
 }
开发者ID:xstation1021,项目名称:kdkitchen,代码行数:49,代码来源:Uploader.php

示例6: 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;
 }
开发者ID:ywarnier,项目名称:php-etl,代码行数:22,代码来源:JsonExtractor.php

示例7: 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();
     }
 }
开发者ID:Alpha-Hydro,项目名称:alpha-hydro-antares,代码行数:18,代码来源:CsvCatalogGeneratorController.php

示例8: hasChildren

 public function hasChildren()
 {
     echo 'MyArrIter::hasChildren = ', var_export(parent::hasChildren()), "\n";
     return parent::hasChildren();
 }
开发者ID:jinguanio,项目名称:david,代码行数:5,代码来源:iterator_run.php

示例9: hasChildren

 function hasChildren()
 {
     echo __METHOD__ . "()\n";
     self::fail(1, __METHOD__);
     return parent::hasChildren();
 }
开发者ID:badlamer,项目名称:hhvm,代码行数:6,代码来源:iterator_047.php

示例10: 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;
 }
开发者ID:AndyRocioGtz,项目名称:Registros,代码行数:16,代码来源:openerp.class.php

示例11: 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();
     }
 }
开发者ID:myurasov,项目名称:rest-api-tools,代码行数:23,代码来源:AbstractRESTController.php

示例12: RecursiveArrayIterator

<?php

error_reporting(E_ALL);
$it = new RecursiveArrayIterator(array('A', 'B', array('C', 'D'), array(array('E', 'F'), array('G', 'H', 'I'))));
// $it is a RecursiveIterator but also an Iterator,
// so it loops normally over the four elements
// of the array.
echo "Foreach over a RecursiveIterator: \n";
foreach ($it as $value) {
    print_r($value);
    // but RecursiveIterators specify additional
    // methods to explore children nodes
    $children = $it->hasChildren() ? '{Yes}' : '{No}';
    echo $children, ' ';
}
echo "\n";
// we can bridge it to a different contract via
// a RecursiveIteratorIterator, whose cryptic name
// should be read as 'an Iterator that spans over
// a RecursiveIterator'.
echo "Foreach over a RecursiveIteratorIterator: \n";
foreach (new RecursiveIteratorIterator($it) as $value) {
    echo $value;
}
echo "\n";
开发者ID:jinguanio,项目名称:david,代码行数:25,代码来源:iterator.php

示例13: 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();
     }
 }
开发者ID:haldayne,项目名称:customs,代码行数:20,代码来源:UploadIterator.php

示例14: 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;
    }
}
开发者ID:GrUSP,项目名称:php_best_practices,代码行数:19,代码来源:recursive_array_iterator.php

示例15: BuildFeed

    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;
    }
开发者ID:rjon76,项目名称:netspotapp,代码行数:32,代码来源:classFeed.php


注:本文中的RecursiveArrayIterator::hasChildren方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。