本文整理汇总了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);
}