PHP Version
4+
$array = ['orange', 'banana', 'apple'];

// Removes the first element from the array
array_shift($array);
print_r($array);
/*
Output:
    Array
    (
        [0] => banana
        [1] => apple
    )
*/
array_shift(array &$array): mixed
// Initialize the array
$array = ['orange', 'banana', 'apple'];

// Remove the first element from the array
$removedItem = array_shift($array);
print_r($array);
/*
Output:
    Array
    (
        [0] => banana
        [1] => apple
    )
*/

echo $removedItem; // Output: 'orange'

// Empty array
$emptyArray = [];
$emptyArray_removedItem = array_shift($emptyArray); // Array is empty, no element to remove

var_dump($emptyArray_removedItem); // Output: NULL
$fruits = ['apple', 'banana', 'cherry'];
$removedFruit = array_shift($fruits);
echo $removedFruit; // Output: 'apple'
$fruits = ['apple', 'banana', 'cherry'];
array_shift($fruits);
echo count($fruits); // Output: 2
$assocArray = ['name' => 'John', 'age' => 30];
array_shift($assocArray);
print_r($assocArray);
/*
Output:
    Array
    (
        [age] => 30
    )
*/
// Create an initial request queue
$requestQueue = [];

// Add requests to the queue
$requestQueue[] = 'Request 1';
$requestQueue[] = 'Request 2';
$requestQueue[] = 'Request 3';

// Process requests
while ($request = array_shift($requestQueue)) {
    // Process the request
    echo "Processing: $request";

    // Simulate a random processing time
    $processingTime = rand(1, 3);
    sleep($processingTime); // Wait for simulated processing time

    echo "Completed: $request";
}

// Code to run after all requests have been processed
echo "All requests have been processed";
// Original array
$fruits = ['apple', 'banana', 'cherry'];

// Remove the first element using unset()
unset($fruits[0]);

// Output the array
print_r($fruits);
/*
Output:
    Array
    (
        [0] => banana
        [1] => cherry
    )
*/