Iterate with foreach (Loops). Every array also carries an internal pointer, moved by next(), prev(), reset() and end() and read by current() and key(), which return false past either end. array_push()/array_pop() use the tail as a stack, and array_shift()/ array_unshift() the head as a queue, renumbering integer keys.
<?php
$queue = ['BK-101', 'BK-205', 'BK-300'];
array_push($queue, 'BK-410', 'BK-512'); array_unshift($queue, 'RUSH-1'); // tail, head
echo array_shift($queue), ' ', array_pop($queue), ' ', json_encode($queue), "\n";
$a = ['x' => 'Dune', 'y' => 'Emma', 'z' => 'Ariel'];
echo current($a), ' ', next($a), ' ', key($a), ' ', end($a), ' ', prev($a), ' ', reset($a);
next($a);
foreach ($a as $v) {} // foreach leaves the pointer alone
echo ' | ', key($a), "\n";
$rng = new Random\Randomizer(new Random\Engine\Mt19937(2026)); // seeded: repeatable
echo json_encode($rng->pickArrayKeys($a, 2)), ' ',
json_encode($rng->shuffleArray($queue)), "\n";Output
RUSH-1 BK-512 ["BK-101","BK-205","BK-300","BK-410"] Dune Emma y Ariel Emma Dune | y ["y","z"] ["BK-205","BK-101","BK-410","BK-300"]
Since PHP 7 foreach leaves the internal pointer alone, so key() still says y; each() was removed in PHP 8.0. array_rand() and shuffle() use the global generator, while Random\Randomizer (PHP 8.2) takes an engine: seeded Mt19937 repeats its picks for tests, and the default Secure engine suits prize draws.