apple [1] => banana [2] => cherry [3] => date [4] => elderberry ) */ // Pop: Remove and return the last element $lastFruit = array_pop($fruits); echo "Popped fruit: " . $lastFruit . " "; echo "After popping: "; print_r($fruits); /* Output: Popped fruit: elderberry After popping: Array ( [0] => apple [1] => banana [2] => cherry [3] => date ) */ // --- Queue Operations (First In, First Out - FIFO) --- echo " --- Queue Operations (FIFO) --- "; // Unshift: Add element(s) to the beginning of the array array_unshift($fruits, 'apricot', 'blueberry'); echo "After unshifting 'apricot' and 'blueberry': "; print_r($fruits); /* Output: Array ( [0] => apricot [1] => blueberry [2] => apple [3] => banana [4] => cherry [5] => date ) */ // Shift: Remove and return the first element $firstFruit = array_shift($fruits); echo "Shifted fruit: " . $firstFruit . " "; echo "After shifting: "; print_r($fruits); /* Output: Shifted fruit: apricot After shifting: Array ( [0] => blueberry [1] => apple [2] => banana [3] => cherry [4] => date ) */ // Practical example: processing a list of tasks as a queue $tasks = ['Download files', 'Process data', 'Upload results']; echo " --- Task Processing Queue --- "; while (!empty($tasks)) { $currentTask = array_shift($tasks); echo "Processing task: " . $currentTask . " "; // Simulate work, e.g., perform an action related to $currentTask } echo "All tasks processed. "; ?>