本文整理匯總了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());
}
}
示例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);
}
示例3: getItemsRawTree
/**
* @param string|null $keyName
* @return array[]
*/
public function getItemsRawTree($keyName = null)
{
return CM_Util::getArrayTree($this->getItemsRaw(), 1, true, $keyName);
}