本文整理汇总了PHP中Collection::sort方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::sort方法的具体用法?PHP Collection::sort怎么用?PHP Collection::sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection::sort方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sort
public function sort($sorter = NULL)
{
if (!isset($sorter)) {
$sorter = array('Words', 'sorter');
}
return parent::sort($sorter);
}
示例2: testSort
public function testSort()
{
$this->collection->sort(function ($a, $b) {
if (preg_match('#^7.#', phpversion())) {
return $a['age'] > $b['age'];
} else {
return $a['age'] >= $b['age'];
}
});
$this->assertEquals([$this->_1, $this->_3, $this->_2, $this->_0], $this->collection->toArray());
}
示例3: sortByYear
/**
* Sorts given collection by release date.
*
* @param Collection $col
* @return Collection
*/
public static function sortByYear($col)
{
$col->sort(function ($a, $b) {
preg_match('/(\\d{4})/', $a->release_date ? $a->release_date : $a->year, $m);
$a = isset($m[0]) ? $m[0] : '';
preg_match('/(\\d{4})/', $b->release_date ? $b->release_date : $b->year, $m);
$b = isset($m[0]) ? $m[0] : '';
if ($a === $b) {
return 0;
}
return $a < $b ? 1 : -1;
});
return $col;
}
示例4: generateMSPRHTML
//.........这里部分代码省略.........
if (++$research_no > MAX_RESEARCH) {
break;
}
?>
<tr>
<td valign="top"><?php
echo nl2br($entity->getText());
?>
</td>
</tr>
<?php
}
?>
</table>
<br>
<?php
}
$internal_awards = $mspr["Internal Awards"];
$external_awards = $mspr["External Awards"];
if ($external_awards) {
$external_awards->filter("is_approved");
}
$component = new Collection();
if ($internal_awards) {
foreach ($internal_awards as $award) {
$component->push($award);
}
}
if ($external_awards) {
foreach ($external_awards as $award) {
$component->push($award);
}
}
$component->sort("year", "asc");
if ($component->count() > 0) {
?>
<h3><u>Academic Awards</u></h3>
<i>A brief summary of the terms of reference accompanies each award. Only items of academic significance and either acknowledged or awarded by Queen's University are presented.</i><br><br>
<table width="100%" border=0 cellpadding=5 cellspacing=0>
<?php
foreach ($component as $entity) {
$award = $entity->getAward();
?>
<tr>
<td valign="top" width="50%"><?php
echo $award->getTitle();
?>
</td>
<td valign="top" width="50%" align="right"><?php
echo $entity->getAwardYear();
?>
</td>
</tr>
<tr>
<td valign="top" colspan=2><blockquote><?php
echo nl2br($award->getTerms());
?>
</blockquote></td>
</tr>
<?php
}
?>
</table>
<br>
<?php
}