PHP 7.4.0beta4 released!

pht\Queue::front

(PECL pht >= 0.0.1)

pht\Queue::frontReturns the first value from a queue

Description

public pht\Queue::front ( void ) : mixed

This method will remove a value from the front of the queue (in constant time). Attempting to return the front value from an empty queue will result in an Error exception.

Attention

Due to the fact that all values in a pht\Queue are serialised, extracting a value from the queue will require it to be deserialised. This can incur a noticeable performance hit if the inspection of the queue's front value is performed within a loop.

Liste de param├Ętres

Cette fonction ne contient aucun param├Ętre.

Valeurs de retour

The value on the front of the queue.

Exemples

Exemple #1 Retrieving the front value of a queue

<?php

use pht\Queue;

$queue = new Queue();

$queue->push(1);

var_dump($queue->front());

L'exemple ci-dessus va afficher :

int(1)

Exemple #2 Retrieving the front value in a loop (bad example - don't do this)

<?php

use pht\Queue;

$queue = new Queue();

$queue->push(array_fill(020000));

for (
$i 0$i count($queue->front()); ++$i); // quadratic runtime

Exemple #3 Retrieving the front value in a loop (good example)

<?php

use pht\Queue;

$queue = new Queue();

$queue->push(array_fill(020000));

$front $queue->front(); // create a separate variable
for ($i 0$i count($front); ++$i); // linear runtime

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top