提问人:machump 提问时间:10/17/2019 更新时间:10/17/2019 访问量:38
PHP 数组 - 将每个元素的数字(值)附加到字符串(键)
PHP array - appending number (value) to string (key) for each element
问:
我有一个数组,比如
$a = array
(
"Leafs",
"Sabres",
"Red Wings",
"Flyers"
);
我洗牌shuffle($a);
生成的数组可以是:
Array
(
[0] => Sabres
[1] => Red Wings
[2] => Leafs
[3] => Flyers
)
对于生成的数组,我现在想将一个序列号附加两次,从 开头 到 数组中的每个元素,这样就变成了:1
$a
Array
(
[1] => Sabres
[1] => Red Wings
[2] => Leafs
[2] => Flyers
)
该数字在此数组中以结尾,但应继续,直到数组中没有更多要编号的元素。如何以编程方式完成此操作?2
答: 暂无答案
上一个:按顺序排列列表
评论
[1] => Sabres [1] => Red Wings
array ( 1 => array( 'Sabres', 'Red Wings', ), 2 => array( 'Leafs',, 'Flyers' ) )
Sabres
1
array_chunk($array,2)