php pop/push/shift/unshift, which to use for queues and which for stacks
<p>In PHP there are two ways to use an array as a <strong>stack</strong> (LIFO)<br/>
and two ways to use them as a <strong>queue</strong> (FIFO).</p>

<p>One could implement a <strong>stack</strong> with <code>push</code> &amp; <code>pop</code>,<br/>
but the same can be done with <code>unshift</code> &amp; <code>shift</code>.</p>

<p>Similarly one could implement a <strong>queue</strong> with <code>push</code> &amp; <code>shift</code>,<br/>
but the same can be done with <code>unshift</code> &amp; <code>pop</code>.</p>

<p>To demonstrate:</p>

<pre><code>echo "stack push &amp; pop approach:\n";
$s = []; array_push($s, 'first'); array_push($s, 'second'); array_push($s, 'third');
echo     array_pop($s) . '-' .    array_pop($s) . '-' .     array_pop($s) .  "\n";
echo "stack unshift &amp; shift approach:\n";
$s = []; array_unshift($s, 'first'); array_unshift($s, 'second'); array_unshift($s, 'third');
echo     array_shift($s) . '-' .     array_shift($s) . '-' .      array_shift($s) .  "\n";
echo "queue push &amp; shift approach:\n";
$q = []; array_push($q, 'first'); array_push($q, 'second'); array_push($q, 'third');
echo     array_shift($q) . '-' .  array_shift($q) . '-' .   array_shift($q) .  "\n";
echo "queue unshift &amp; pop approach:\n";
$q = []; array_unshift($q, 'first'); array_unshift($q, 'second'); array_unshift($q, 'third');
echo     array_pop($q) . '-' .       array_pop($q) . '-' .        array_pop($q) .       "\n";
</code></pre>

<p>Which outputs:</p>

<pre><code>stack push &amp; pop approach:
third-second-first
stack unshift &amp; shift approach:
third-second-first
queue push &amp; shift approach:
first-second-third
queue unshift &amp; pop approach:
first-second-third
</code></pre>

<p>So which sets of functions to use?!</p>