php pop/push/shift/unshift, which to use for queues and which for stacks
问题 In PHP there are two ways to use an array as a stack (LIFO) and two ways to use them as a queue (FIFO). One could implement a stack with push & pop , but the same can be done with unshift & shift . Similarly one could implement a queue with push & shift , but the same can be done with unshift & pop . To demonstrate: echo "stack push & pop approach:\n"; $s = []; array_push($s, 'first'); array_push($s, 'second'); array_push($s, 'third'); echo array_pop($s) . '-' . array_pop($s) . '-' . array