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


PHP RecursiveArrayIterator::key方法代码示例

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


在下文中一共展示了RecursiveArrayIterator::key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
    }
}
开发者ID:Eldahar,项目名称:PHP_Library,代码行数:12,代码来源:RecursiveArrayIterator1.php

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

示例3: 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;
 }
开发者ID:nextframework,项目名称:next,代码行数:35,代码来源:ArrayUtils.php

示例4: 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));
         }
     }
 }
开发者ID:hpaul,项目名称:Google-short,代码行数:23,代码来源:finder.php

示例5: current

 /** @return key() since that is the name we need
  */
 function current()
 {
     $result = parent::key();
     $parent = get_parent_class($result);
     if ($parent) {
         $interfaces = array_diff(class_implements($result), class_implements($parent));
         if ($interfaces) {
             $implements = array();
             foreach ($interfaces as $interface) {
                 $implements = array_merge($implements, class_implements($interface));
             }
             $interfaces = array_diff($interfaces, $implements);
             natcasesort($interfaces);
             $result .= ' (' . join(', ', $interfaces) . ')';
         }
     }
     return $result;
 }
开发者ID:cefalo19,项目名称:php-src,代码行数:20,代码来源:class_tree.php

示例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;
}
开发者ID:nicholasruunu,项目名称:Arbetsprov,代码行数:31,代码来源:MY_array_helper.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: search_in_array

 private function search_in_array($needle, $haystack)
 {
     $array_iterator = new RecursiveArrayIterator($haystack);
     $iterator = new RecursiveIteratorIterator($array_iterator);
     while ($iterator->valid()) {
         if ($iterator->current() == $needle) {
             return $array_iterator->key();
         }
         $iterator->next();
     }
     return false;
 }
开发者ID:ahmedalaahagag,项目名称:HospitalManagementSystem,代码行数:12,代码来源:booking_class.php

示例9: unsetEmpty

 /**
  * Unset empty
  * @param $values
  * @return array
  */
 protected function unsetEmpty($values)
 {
     if (empty($values)) {
         return $values;
     }
     $values = array_filter($values, function ($value) {
         return $value !== null && $value !== '';
     });
     $result = array();
     $iterator = new RecursiveArrayIterator($values);
     $recursive = new RecursiveIteratorIterator($iterator);
     foreach ($recursive as $key => $value) {
         $value = JString::trim($value);
         if ($value !== '' && $value !== null) {
             $depth = $recursive->getDepth();
             $depth--;
             $subKey = null;
             $subIterator = $recursive->getSubIterator($depth);
             if ($subIterator) {
                 $subKey = $subIterator->key();
             }
             if ($subKey && $subKey != $iterator->key()) {
                 $result[$iterator->key()][$subKey][$key] = $value;
             } elseif ($iterator->key() != $key) {
                 $result[$iterator->key()][$key] = $value;
             } else {
                 $result[$key] = $value;
             }
         }
     }
     return $result;
 }
开发者ID:alexmixaylov,项目名称:real,代码行数:37,代码来源:jbmodel.element.jbprice.php

示例10: 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

示例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: 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

示例13: current

 /** @return key() since that is the name we need
  */
 function current()
 {
     return parent::key();
 }
开发者ID:kennyb,项目名称:php-broken,代码行数:6,代码来源:class_tree.php

示例14: array

<?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();
}
开发者ID:AtiqulHaque,项目名称:phprightway,代码行数:11,代码来源:ReccursivrArrayClass.php

示例15: 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;
 }
开发者ID:NavaINT1876,项目名称:ccustoms,代码行数:21,代码来源:data.php


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