Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A bit more detail.<br></p> <h2>Functionality</h2> <ol> <li><p><code>array_pop()</code><strong>pops</strong> an element off <strong>end</strong> of the array.</p></li> <li><p><code>array_push()</code> <strong>pushes</strong> an element into the <strong>end</strong> of the array.</p></li> <li><p><code>array_shift()</code> <strong>pops</strong> an element off the <strong>beginning</strong> of the array.</p></li> <li><p><code>array_unshift()</code> <strong>pushes</strong> an element into the <strong>beginning</strong> of the array.<br><br></p></li> </ol> <h2>Beautiful Matrix</h2> <p>Here’s a beautiful matrix that shows each function in respect to the others. Notice the symbolic arrows.</p> <blockquote> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Beginning</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>End</strong><br /> <strong>Pop</strong> from&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;-<code>array_shift()</code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>array_pop()</code>-&gt;<br /> <strong>Push</strong> into&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&gt;<code>array_unshift()</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>array_push()</code>&lt;-</p> </blockquote> <p>It was <em>real</em> uneasy to create it with SO’s markup restrictions. Click on edit to check out the source (and of course feel free to enhance it)!<br><br></p> <h2>Shift VS. Unshift confusion</h2> <p>So. When trying to memorize all 4 functions, it was very easy for me to learn what <code>array_pop()</code> does: <em>it just pops an element off the end of array</em>. Naturally, the functionality of the complementary <code>array_push()</code> was absolutely clear from the first shot too: <em>it pushes an element back into the end</em>. However, the two opposite brothers <code>array_shift()</code> and <code>array_unshift()</code> kept giving me hard time when I was trying to remember which one <em>pops</em> and which one <em>pushes</em>. :-/ I had to constantly look it up.</p> <p>Funny, the solution I came up with was simply the <strong>letter “U”</strong>. Those that have it: <code>array_pUsh()</code> and <code>array_Unshift()</code> - pUsh. The other two - pop. Easy-peasy!</p> <p>Hope this helps anyone!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload