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


PHP CMbArray::searchRecursive方法代码示例

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


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

示例1: testSearchRecursive

 public function testSearchRecursive()
 {
     $array = array("key1" => "val1", array("key2" => "val2", array("key3" => "val3")));
     $this->assertEquals(array("key1"), $this->stub->searchRecursive("val1", $array));
     $this->assertEquals(array(array(array("key3"))), $this->stub->searchRecursive("val3", $array));
 }
开发者ID:fbone,项目名称:mediboard4,代码行数:6,代码来源:CMbArrayTest.php

示例2: searchRecursive

 /**
  * A recursive version of array_search (works for multidimensional array).
  * The result is an array reproducing the structure of the haystack
  *
  * @param mixed $needle   The needle
  * @param array $haystack The haystack
  *
  * @return array
  */
 static function searchRecursive($needle, $haystack)
 {
     $path = array();
     foreach ($haystack as $id => $val) {
         if ($val === $needle) {
             $path[] = $id;
             break;
         } elseif (is_array($val)) {
             $found = CMbArray::searchRecursive($needle, $val);
             if (count($found) > 0) {
                 $path[$id] = $found;
                 break;
             }
         }
     }
     return $path;
 }
开发者ID:fbone,项目名称:mediboard4,代码行数:26,代码来源:CMbArray.class.php

示例3: sortConstantsbyGraph

 /**
  * Sort the constants by rank, and create a structure for dividing the constants in graphs
  *
  * @param CConstantesMedicales[] $constants The CConstantesMedicales objects who contain the values for the constants
  *
  * @return array
  */
 function sortConstantsbyGraph($constants)
 {
     $constants_list = array();
     $constants_by_graph = array();
     $constants_by_rank = CConstantesMedicales::getConstantsByRank('graph', false, $this->host);
     /* The valued constants are sorted by rank */
     foreach (CConstantesMedicales::$list_constantes as $cst_name => $cst_attr) {
         if (substr($cst_name, 0, 1) == '_' && !isset($cst_attr['plot'])) {
             continue;
         }
         foreach ($constants as $cst) {
             if (!is_null($cst->{$cst_name}) && array_search($cst_name, $constants_list) === false) {
                 $rank = CMbArray::searchRecursive($cst_name, $constants_by_rank);
                 if (empty($rank)) {
                     continue;
                 }
                 $rank = array_keys($rank['all']);
                 $rank = $rank[0];
                 if (!array_key_exists($rank, $constants_by_graph)) {
                     $constants_by_graph[$rank] = array();
                 }
                 $constants_by_graph[$rank][] = $cst_name;
                 $constants_list[] = $cst_name;
             }
         }
     }
     /* We remove the constant with the rank 0, sort the array and add the rank 0 at the end of the array */
     $hidden_cst = null;
     if (array_key_exists('hidden', $constants_by_graph)) {
         $hidden_cst = $constants_by_graph['hidden'];
         unset($constants_by_graph['hidden']);
     }
     ksort($constants_by_graph);
     if (!is_null($hidden_cst)) {
         $constants_by_graph['hidden'] = $hidden_cst;
     }
     $stacked_graphs = CConstantesMedicales::getHostConfig('stacked_graphs', $this->host);
     foreach ($constants_by_graph as $_rank => $_constants) {
         $constants_by_graph[$_rank] = array();
         if ($_rank != 'hidden' && $stacked_graphs) {
             $cumuls_constants = array();
             foreach ($_constants as $_key => $_constant) {
                 /* The constants with a cumul can't be stacked with other constants */
                 if (isset(CConstantesMedicales::$list_constantes[$_constant]['cumul_reset_config'])) {
                     unset($_constants[$_key]);
                     $cumuls_constants[] = $_constant;
                 }
             }
             /* The number of constants by graph is limited to 5 */
             if (count($_constants) > 5) {
                 $constants = array();
                 for ($i = 0; $i < count($_constants); $i = $i + 5) {
                     $constants[] = array_slice($_constants, $i, 5);
                 }
                 foreach ($cumuls_constants as $_key => $_cumul) {
                     $cumuls_constants[$_key] = array($_cumul);
                 }
                 $constants_by_graph[$_rank] = array_merge($constants, $cumuls_constants);
             } else {
                 if (!empty($_constants)) {
                     $constants_by_graph[$_rank][] = $_constants;
                 }
                 foreach ($cumuls_constants as $_cumul) {
                     $constants_by_graph[$_rank][] = array($_cumul);
                 }
             }
         } else {
             /* The constants with a rank of 0 can't be stacked */
             foreach ($_constants as $_constant) {
                 $constants_by_graph[$_rank][] = array($_constant);
             }
         }
     }
     $this->structure = $constants_by_graph;
 }
开发者ID:fbone,项目名称:mediboard4,代码行数:82,代码来源:CConstantGraph.class.php


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