PHP Ds\PriorityQueue peek() Function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The Ds\PriorityQueue::peek() Function in PHP is used to get the value present at the front of a PriorityQueue. Syntax: mixed public Ds\PriorityQueue::peek ( void ) Parameters: This function does not accepts any parameters. Return Value: This function returns the value present at the front of this PriorityQueue. The return type of the function is mixed and depends on the type of value stored in the PriorityQueue. Exception: This function throws an UnderflowException if the PriorityQueue is empty. Below programs illustrate the Ds\PriorityQueue::peek(): Program 1: php <?php // Declare new PriorityQueue $pq = new \Ds\PriorityQueue(); // Add elements to the PriorityQueue $pq->push("One", 1); $pq->push("Two", 2); $pq->push("Three", 3); echo "PriorityQueue is: \n"; print_r($pq); // Get element at the front echo "\nElement at front is: "; print_r($pq->peek()); ?> Output: PriorityQueue is: Ds\PriorityQueue Object ( [0] => Three [1] => Two [2] => One ) Element at front is: Three Program 2: php <?php // Declare new PriorityQueue $pq = new \Ds\PriorityQueue(); echo "PriorityQueue is: \n"; print_r($pq); // Get element at the front echo "\nElement at front is: "; print_r($pq->peek()); ?> Output: PHP Fatal error: Uncaught UnderflowException Reference: https://www.php.net/manual/en/ds-priorityqueue.peek.php Comment More infoAdvertise with us Next Article PHP SplPriorityQueue isEmpty() Function G gopaldave Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_priorityqueue Similar Reads PHP SplPriorityQueue key() Function The SplPriorityQueue::key() function is an inbuilt function in PHP that is used to return the current node index. Syntax: mixed SplPriorityQueue::key() Parameters: This function does not accept any parameter. Return Value: This function returns the current node index. Example: PHP <?php // Declar 1 min read PHP SplPriorityQueue next() Function The SplPriorityQueue::next() function is an inbuilt function in PHP that is used to extract the top node from the queue. Syntax: void SplPriorityQueue::next() Parameters: This function does not accept any parameter. Return Value: This function does not return any value. Example: PHP <?php // Decl 1 min read PHP SplPriorityQueue insert() Function The SplPriorityQueue::insert() function is an inbuilt function in PHP which is used to inserts an element in the queue by sifting the elements. Insert elements in priority queue by given priority. Syntax: bool SplPriorityQueue::insert( mixed $value, mixed $priority ) Parameters: This function accept 2 min read PHP SplPriorityQueue isEmpty() Function The SplPriorityQueue::isEmpty() function is an inbuilt function in PHP that is used to check whether the queue is empty or not. Syntax: bool SplPriorityQueue::isEmpty() Parameters: This function does not accept any parameter. Return Value: This function returns a boolean value either true or false d 1 min read PHP SplPriorityQueue count() Function The SplPriorityQueue::count() function is an inbuilt function in PHP which is used to count the number of elements in the queue. Syntax: int SplPriorityQueue::count() Parameters: This function does not accept any parameters. Return Value: This function returns the number of elements in the queue. Ex 1 min read PHP SplPriorityQueue isCorrupted() Function The SplPriorityQueue::isCorrupted() function is an inbuilt function in PHP that is used to tells the priority queue is in a corrupted state or not. Syntax: bool SplPriorityQueue::isCorrupted() Parameters: This function does not accept any parameter. Return Value: This function returns true if the pr 1 min read Like