本文整理汇总了PHP中Set::nest方法的典型用法代码示例。如果您正苦于以下问题:PHP Set::nest方法的具体用法?PHP Set::nest怎么用?PHP Set::nest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Set
的用法示例。
在下文中一共展示了Set::nest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMissingParent
/**
* test Set nest with no specified parent data.
*
* The result should be the same as the input.
* For an easier comparison, unset all the empty children arrays from the result
*
* @return void
*/
public function testMissingParent()
{
$input = array(array('id' => 1), array('id' => 2), array('id' => 3), array('id' => 4), array('id' => 5), array('id' => 6), array('id' => 7), array('id' => 8), array('id' => 9), array('id' => 10));
$result = Set::nest($input, array('idPath' => '/id', 'parentPath' => '/parent_id'));
foreach ($result as &$row) {
if (empty($row['children'])) {
unset($row['children']);
}
}
$this->assertEquals($input, $result);
}
示例2: _findThreaded
/**
* In the event of ambiguous results returned (multiple top level results, with different parent_ids)
* top level results with different parent_ids to the first result will be dropped
*
* @param mixed $state
* @param mixed $query
* @param array $results
* @return array Threaded results
*/
protected function _findThreaded($state, $query, $results = array())
{
if ($state === 'before') {
return $query;
} elseif ($state === 'after') {
$parent = 'parent_id';
if (isset($query['parent'])) {
$parent = $query['parent'];
}
return Set::nest($results, array('idPath' => '/' . $this->alias . '/' . $this->primaryKey, 'parentPath' => '/' . $this->alias . '/' . $parent));
}
}