假设我有下表:
name
----
A
B
C
D
E
F
G
H
I
我可以从 MySQL 中提取它并将其放入一个数组中:
$result = mysql_query("SELECT * FROM names ORDER BY name DESC");
while ($row = mysql_fetch_object($result)) {
$names[] = $row->name
}
我现在正在寻找的是一个循环$names
并返回对的脚本,例如每个第三个名称:
array(
[A] => [C],
[B] => [D],
[C] => [E],
[D] => [F]
[E] => [G]
[F] => [H]
[G] => [I]
)
或者,例如,每 4 个名称:
array(
[A] => [D],
[B] => [E],
[C] => [F],
[D] => [G]
[E] => [H]
[F] => [I]
)
中间的名称数量(第一个示例中为 3 个,第二个示例中为 4 个)应该是可变的。有人知道如何在 php 中执行此操作吗?