数组第一个值重复3次

时间:2016-06-13 16:19:15

标签: php arrays

$ array =

Array
(
    [0] => Array
        (
            [type] => BUILDING_KILL
            [teamId] => 200
        )

    [1] => Array
        (
            [type] => BUILDING_KILL
            [teamId] => 100
        )

    [2] => Array
        (
            [type] => BUILDING_KILL
            [teamId] => 200
        )

    [3] => Array
        (
            [type] => BUILDING_KILL
            [teamId] => 100
        )

    [4] => Array
        (
            [type] => BUILDING_KILL
            [teamId] => 200
        )

    [5] => Array
        (
            [type] => BUILDING_KILL
            [teamId] => 200
        )

    [6] => Array
        (
            [type] => BUILDING_KILL
            [teamId] => 100
        )
    [7] => Array
        (
            [type] => BUILDING_KILL
            [teamId] => 200
        )

)

[teamID] => 200先重复3次。

如何动态地将200保存到$firsttogive3towers变量中。

数组数据并不总是相同。我不知道怎么做,所以我来到这里。

我希望我能很好地解释我的问题。

为什么要投票,我问一个愚蠢的问题或违反任何规则?

编辑:已解决

1 个答案:

答案 0 :(得分:0)

如果我正确理解你,你正试图将前三个teamID推入数组$firsttogive3towers。如果是这样,这将实现:

for($i = 0; $i < 3; $i++) {
   array_push($firsttogive3towers, $array[$i]['teamID']);
}