Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<Ds\Queue::toArrayDs\PriorityQueue::allocate>
^Data StructuresLast updated: Mon, 26 Oct 2026

The PriorityQueue class

(PECL ds >= 1.0.0)

Introduction

A PriorityQueue is very similar to a Queue. Values are pushed into the queue with an assigned priority, and the value with the highest priority will always be at the front of the queue.

Implemented using a max heap.

Note:

"First in, first out" ordering is preserved for values with the same priority.

Note:

Iterating over a PriorityQueue is destructive, equivalent to successive pop operations until the queue is empty.

Class synopsis

class Ds\PriorityQueue implements Ds\Collection {
/* Constants */
const int MIN_CAPACITY = 8;
/* Methods */
public function allocate(int $capacity): void
public function capacity(): int
public function clear(): void
public function copy(): Ds\PriorityQueue
public function isEmpty(): bool
public function peek(): mixed
public function pop(): mixed
public function push(mixed $value, int $priority): void
public function toArray(): array
}

Predefined Constants

Ds\PriorityQueue::MIN_CAPACITY

Table of Contents


<Ds\Queue::toArrayDs\PriorityQueue::allocate>
^Data StructuresLast updated: Mon, 26 Oct 2026