當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CM_Util::getArrayTree方法代碼示例

本文整理匯總了PHP中CM_Util::getArrayTree方法的典型用法代碼示例。如果您正苦於以下問題:PHP CM_Util::getArrayTree方法的具體用法?PHP CM_Util::getArrayTree怎麽用?PHP CM_Util::getArrayTree使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CM_Util的用法示例。


在下文中一共展示了CM_Util::getArrayTree方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testGetArrayTree

 public function testGetArrayTree()
 {
     $array = array(array('id' => 1, 'type' => 1, 'amount' => 1), array('id' => 2, 'type' => 1, 'amount' => 2), array('id' => 3, 'type' => 1, 'amount' => 3), array('id' => 4, 'type' => 1, 'amount' => 4));
     $this->assertSame(array(1 => array('type' => 1, 'amount' => 1), 2 => array('type' => 1, 'amount' => 2), 3 => array('type' => 1, 'amount' => 3), 4 => array('type' => 1, 'amount' => 4)), CM_Util::getArrayTree($array));
     $this->assertSame(array(1 => array('id' => 1, 'type' => 1), 2 => array('id' => 2, 'type' => 1), 3 => array('id' => 3, 'type' => 1), 4 => array('id' => 4, 'type' => 1)), CM_Util::getArrayTree($array, 1, true, 'amount'));
     $this->assertSame(array(1 => array(1 => 1), 2 => array(1 => 2), 3 => array(1 => 3), 4 => array(1 => 4)), CM_Util::getArrayTree($array, 2, true, array('amount', 'type')));
     try {
         CM_Util::getArrayTree($array, 1, true, 'foo');
         $this->fail('Item has key `foo`.');
     } catch (CM_Exception_Invalid $ex) {
         $this->assertContains('Item has no key `foo`.', $ex->getMessage());
     }
     try {
         CM_Util::getArrayTree(array(1, 2));
         $this->fail('Item is not an array.');
     } catch (CM_Exception_Invalid $ex) {
         $this->assertContains('Item is not an array or has less than `2` elements.', $ex->getMessage());
     }
     try {
         CM_Util::getArrayTree(array(array(1), array(2)));
         $this->fail('Item has less than two elements.');
     } catch (CM_Exception_Invalid $ex) {
         $this->assertContains('Item is not an array or has less than `2` elements.', $ex->getMessage());
     }
 }
開發者ID:aladin1394,項目名稱:CM,代碼行數:25,代碼來源:UtilTest.php

示例2: fetchAllTree

 /**
  * @param int|null  $level
  * @param bool|null $distinctLeaves
  * @return array[]
  */
 public function fetchAllTree($level = null, $distinctLeaves = null)
 {
     return CM_Util::getArrayTree($this->fetchAll(), $level, $distinctLeaves);
 }
開發者ID:cargomedia,項目名稱:cm,代碼行數:9,代碼來源:Result.php

示例3: getItemsRawTree

 /**
  * @param string|null $keyName
  * @return array[]
  */
 public function getItemsRawTree($keyName = null)
 {
     return CM_Util::getArrayTree($this->getItemsRaw(), 1, true, $keyName);
 }
開發者ID:cargomedia,項目名稱:cm,代碼行數:8,代碼來源:Abstract.php


注:本文中的CM_Util::getArrayTree方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。