Say I have the following table:
name
----
A
B
C
D
E
F
G
H
I
I can extract this from MySQL and put it in an array:
$result = mysql_query("SELECT * FROM names ORDER BY name DESC");
while ($row = mysql_fetch_object($result)) {
$names[] = $row->name
}
What I am now looking for is a script that loops through $names
and returns pairs, for instance every 3rd name:
array(
[A] => [C],
[B] => [D],
[C] => [E],
[D] => [F]
[E] => [G]
[F] => [H]
[G] => [I]
)
Or, for instance, every 4th name:
array(
[A] => [D],
[B] => [E],
[C] => [F],
[D] => [G]
[E] => [H]
[F] => [I]
)
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?