Open In App

PHP SplQueue::enqueue() Function

Last Updated : 23 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The SplQueue::enqueue() function is an inbuilt function in PHP which is used to add the element to the queue.

Syntax:

void SplQueue::enqueue( $val )

Parameters: This function accepts a single parameter $val which specifies the value for add (enqueue) element.

Return Value: This function does not return any value.

Below programs illustrate the SplQueue::enqueue() function in PHP:

Program 1:




<?php
  
// Create a new empty queue
$gfg = new SplQueue();
  
$gfg[] = 1;
  
// Enqueue element
$gfg->enqueue(10);
$gfg->enqueue(20);
  
echo $gfg[1] .  "\n";
echo $gfg[2] .  "\n";
  
?>


Output:

10
20

Program 2:




<?php
  
// Create some fixed size array
$gfg = new SplQueue();
  
$gfg[] = 1;
$gfg[] = 5;
$gfg[] = 1;
$gfg[] = 11;
$gfg[] = 15;
$gfg[] = 17;
  
$gfg->enqueue(11);
$gfg->enqueue(12);
$gfg->enqueue(13);
$gfg->enqueue(14);
  
// Print result after enqueue
foreach ($gfg as $elem)  {
    echo $elem."\n";
}
?>


Output:

1
5
1
11
15
17
11
12
13
14

Reference: https://www.php.net/manual/en/splqueue.enqueue.php



Similar Reads

PHP SplQueue::dequeue() Function
The SplQueue::dequeue() function is an inbuilt function in PHP which is used to dequeues the node from the queue. Syntax: mixed SplQueue::dequeue() Parameters: This function does not accept any parameter. Return Value: This function return the value of the dequeued node. Below programs illustrate the SplQueue::dequeue() function in PHP: Program 1:
1 min read
PHP SplQueue::__construct() Function
The SplQueue::__construct() function is an inbuilt function in PHP which is used to construct a queue which is implemented using a doubly-linked list. Syntax: void SplQueue::__construct(void) Parameters: This function does not accept any parameter. Return Value: This function does not return any value. Below programs illustrate the SplQueue::__cons
1 min read
p5.js | Enqueue Operation in Queue
What is Queue? A Queue is a linear structure which follows a particular order in which the operations are performed. The order is First In First Out (FIFO). A good example of a queue is any queue of consumers for a resource where the consumer that came first is served first. It takes constant time to add or remove an element in a queue. Queues shou
3 min read
Implement enqueue and dequeue using only two stacks in JavaScript ?
In this article, we will implement queue's operations (enqueue and dequeue) using only two stacks (in the form of plain arrays) in JavaScript. Before directly jumping into understanding the problem statement let us understand briefly what exactly a stack is and also what exactly a queue is. A stack is a linear data structure that works on the conce
6 min read
How to get the function name inside a function in PHP ?
To get the function name inside the PHP function we need to use Magic constants(__FUNCTION__). Magic constants: Magic constants are the predefined constants in PHP which is used on the basis of their use. These constants are starts and end with a double underscore (__). These constants are created by various extensions. Syntax: $string = __FUNCTION
1 min read
How the User-Defined Function differs from Built-in Function in PHP ?
In PHP, functions are blocks of reusable code that perform specific tasks. They enhance code readability, modularity, and maintainability by encapsulating logic into named units. PHP functions can be categorized into two main types: user-defined functions and built-in functions. User-Defined FunctionsUser-defined functions are functions created by
2 min read
PHP 5 vs PHP 7
PHP is a server side scripting language designed for web development by Rasmus Lerdorf in 1994. Since its launch in 1994 PHP has become an industry standard supporting almost 80% of the websites ( 79.8% to be precise) with its closest competitor being ASP.Net at 19.8% and others like Ruby, Java trailing far behind. The PHP development team released
4 min read
PHP | Get PHP configuration information using phpinfo()
PHP provides us with a built-in function phpinfo() which gives us the details about the PHP version and PHP configuration of PHP installed in our system. To know about the Configurations and PHP version which is installed in your computer, a simple PHP script can be used. The script consists of a PHP function called "phpinfo()" which outputs inform
2 min read
PHP | php.ini File Configuration
At the time of PHP installation, php.ini is a special file provided as a default configuration file. It's very essential configuration file which controls, what a user can or cannot do with the website. Each time PHP is initialized, the php.ini file is read by the system. Sometimes you need to change the behavior of PHP at runtime, then this config
5 min read
How to import config.php file in a PHP script ?
The include statement in PHP copies the code of text from the file mentioned, into the file that uses the include statement. It directs the preprocessor to insert the content specified into the following program. The name of the file to be included is written in double-quotes. It is a good practice to write the basic database details and user detai
2 min read