php8.5
Home/ Manual/ ds / priorityqueue/ Ds\PriorityQueue::peek

Ds\PriorityQueue::peek

PHP function Edit on GitHub ✎

(PECL ds >= 1.0.0)

Returns the value at the front of the queue

Description

Ds\PriorityQueue::peek(): mixed

Returns the value at the front of the queue, but does not remove it.

Parameters Parameters

Return Values

The value at the front of the queue.

Errors/Exceptions

UnderflowException if empty.

Examples

Ds\PriorityQueue::peek() example

php
<?php
$queue = new \Ds\PriorityQueue();

$queue->push("a",  5);
$queue->push("b", 15);
$queue->push("c", 10);

var_dump($queue->peek());
?>

The above example will output something similar to:

output
string(1) "b"

Source: reference/ds/ds/priorityqueue/peek.xml · from the official PHP manual (php/doc-en)