PHP数组-将每个元素的数字(值)附加到字符串(键)上

时间:2019-10-16 17:00:29

标签: php arrays dictionary sequence shuffle

我有一个类似

的数组
$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结尾,但是应该一直持续到该数组中没有其他要编号的元素为止。如何以编程方式完成?

0 个答案:

没有答案