本文整理匯總了PHP中SplPriorityQueue::compare方法的典型用法代碼示例。如果您正苦於以下問題:PHP SplPriorityQueue::compare方法的具體用法?PHP SplPriorityQueue::compare怎麽用?PHP SplPriorityQueue::compare使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SplPriorityQueue
的用法示例。
在下文中一共展示了SplPriorityQueue::compare方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: compare
public function compare($a, $b)
{
if ($b == 2) {
throw new Exception('ignore me');
} else {
return parent::compare($a, $b);
}
}
示例2: compare
/**
* Overrides native default comparison logic to assign higher priority to
* events inserted earlier.
*
* @param \Phergie\Irc\Bot\React\EventQueuePriority $priority1
* @param \Phergie\Irc\Bot\React\EventQueuePriority $priority2
* @return int
*/
public function compare($priority1, $priority2)
{
if (!$priority1 instanceof EventQueuePriority || !$priority2 instanceof EventQueuePriority) {
return parent::compare($priority1, $priority2);
}
$priority = $priority1->value - $priority2->value;
if (!$priority) {
$priority = $priority2->timestamp - $priority1->timestamp;
}
return $priority;
}
示例3: SplPriorityQueue
<?php
$h = new SplPriorityQueue();
var_dump($h->compare(4, 5) < 0);
var_dump($h->compare(5, 5) == 0);
var_dump($h->compare(5, 4) > 0);
?>
===DONE===
示例4: SplPriorityQueue
<?php
$h = new SplPriorityQueue();
$h->compare();
$h->compare(1);
$h->compare(1, 2, 3);