How to create an array of every nth item?
<p>Say I have the following table:</p>

<pre><code>name
----
A
B
C
D
E
F
G
H
I
</code></pre>

<p>I can extract this from MySQL and put it in an array:</p>

<pre><code>$result = mysql_query("SELECT * FROM names ORDER BY name DESC");
while ($row = mysql_fetch_object($result)) {
  $names[] = $row-&gt;name
}
</code></pre>

<p>What I am now looking for is a script that loops through <code>$names</code> and returns pairs, for instance every 3rd name:</p>

<pre><code>array(
  [A] =&gt; [C],
  [B] =&gt; [D],
  [C] =&gt; [E],
  [D] =&gt; [F]
  [E] =&gt; [G]
  [F] =&gt; [H]
  [G] =&gt; [I]
)
</code></pre>

<p>Or, for instance, every 4th name:</p>

<pre><code>array(
  [A] =&gt; [D],
  [B] =&gt; [E],
  [C] =&gt; [F],
  [D] =&gt; [G]
  [E] =&gt; [H]
  [F] =&gt; [I]
)
</code></pre>

<p>The number of names in between (3 in the fist example, 4 in the second) should be variable. Does anybody know how to do this in php?</p>
