May 2017
Intermediate to advanced
340 pages
8h 16m
English
If we do not want any hard time implementing queue functionalities, and are happy with a built-in solution, we can use the SplQueue class for any of our basic queue needs. We have to remember one thing: that there is no peek function available in the SplQueue class. We have to use the bottom() function to get the first element of the queue. Here is the simple queue implementation for our AgentQueue using SplQueue:
$agents = new SplQueue(); $agents->enqueue("Fred"); $agents->enqueue("John"); $agents->enqueue("Keith"); $agents->enqueue("Adiyan"); $agents->enqueue("Mikhael"); echo $agents->dequeue()."\n"; echo $agents->dequeue()."\n"; echo $agents->bottom()."\n";
Read now
Unlock full access