Content · Web Development · PHP

PHP SplPriorityQueue::getExtractFlags() Method: Usage and Examples

Returns the mode controlling whether extraction yields data, priority or both. EXTR_BOTH returns an array with data and priority rather than a scalar.

1 views Published Oct 17, 2026 Updated Oct 17, 2026 admin

Returns the mode controlling whether extraction yields data, priority or both.

The examples focus on the operation itself, including the important distinction: setExtractFlags changes the mode.

What It Does


Use the examples below to observe the behavior on a small dataset before extending it to application code.

Syntax and Return Value


SplPriorityQueue::getExtractFlags()

The displayed signature describes the API or identifies any correction or optional dependency. When a parameter is optional, supply it only when the task requires it.

Example 1: Basic Use


The queue is a max-priority queue; equal priorities have no guaranteed FIFO order. The getExtractFlags call is shown on a small, inspectable dataset.

<?php
$heap = new SplPriorityQueue();
$heap->insert('task-4', 4);
$heap->insert('task-12', 12);
$heap->insert('task-7', 7);
echo $heap->getExtractFlags() === SplPriorityQueue::EXTR_DATA ? "data" : "other";

Output from a successful local PHP 8.4 run:

data

Example 2: Checking Behavior


The queue is a max-priority queue; equal priorities have no guaranteed FIFO order. The getExtractFlags call is shown on a small, inspectable dataset.

<?php
$heap = new SplPriorityQueue();
$heap->insert('task-2', 2);
$heap->insert('task-9', 9);
$heap->insert('task-5', 5);
$heap->insert('task-1', 1);
echo $heap->getExtractFlags() === SplPriorityQueue::EXTR_DATA ? "data" : "other";

Output from a successful local PHP 8.4 run:

data

Example 3: Practical Example


The queue is a max-priority queue; equal priorities have no guaranteed FIFO order. The getExtractFlags call is shown on a small, inspectable dataset.

<?php
$heap = new SplPriorityQueue();
$heap->insert('task-19', 19);
$heap->insert('task-3', 3);
$heap->insert('task-11', 11);
echo $heap->getExtractFlags() === SplPriorityQueue::EXTR_DATA ? "data" : "other";

Output from a successful local PHP 8.4 run:

data

Important Behavior and Edge Cases


EXTR_BOTH returns an array with data and priority rather than a scalar.

Comparison with Related Approaches


ApproachDifference
SplPriorityQueue::getExtractFlagsReturns the mode controlling whether extraction yields data, priority or both.
Related API or alternativesetExtractFlags changes the mode.

Common Beginner Mistakes


MistakeCorrect approach
Ignoring the operation-specific limitsEXTR_BOTH returns an array with data and priority rather than a scalar.
Confusing it with a related APIsetExtractFlags changes the mode.

Key Takeaways


  • Returns the mode controlling whether extraction yields data, priority or both.
  • EXTR_BOTH returns an array with data and priority rather than a scalar.
  • setExtractFlags changes the mode.

Use SplPriorityQueue::getExtractFlags when its documented behavior matches the problem. Test the relevant edge cases in your own runtime before deploying it.

Share this resourceSend this page to someone who may find it useful.