使用Array的X键值创建一个新数组

时间:2016-06-09 12:15:54

标签: php arrays

    Array
(
    [0] => 1
    [1] => Array
        (
            [summonerName] => FOX kfo
            [profileIcon] => 28
        )

    [2] => 2
    [3] => Array
        (
            [summonerName] => FOX Hard
            [profileIcon] => 7
        )

    [4] => 3
    [5] => Array
        (
            [summonerName] => FOX Froggen
            [profileIcon] => 4
        )

    [6] => 4
    [7] => Array
        (
            [summonerName] => FOX Keith
            [profileIcon] => 23
        )

    [8] => 5
    [9] => Array
        (
            [summonerName] => FOX Big
            [profileIcon] => 4
        )

    [10] => 6
    [11] => Array
        (
            [summonerName] => C9 Impact
            [profileIcon] => 7
        )

    [12] => 7
    [13] => Array
        (
            [summonerName] => C9 Meteos
            [profileIcon] => 4
        )

    [14] => 8
    [15] => Array
        (
            [summonerName] => C9 Jensen
            [profileIcon] => 4
        )

    [16] => 9
    [17] => Array
        (
            [summonerName] => C9 Sneaky
            [profileIcon] => 4
        )

    [18] => 10
    [19] => Array
        (
            [summonerName] => C9 Smoothie
            [profileIcon] => 4
        )

)

如何将上面的数组转换为此?

  Array 
(
    [0] => FOX kfo
    [1] => FOX Hard
    [2] => FOX Froggen
    [3] => FOX Keith
    [4] => FOX Big
    [5] => C9 Impact
    [6] => C9 Meteos
    [7] => C9 Jensen
    [8] => C9 Sneaky
    [9] => C9 Smoothie
)

我想制作一个包含所有[summonerName] s。

的数组

由于我的主要语言不是英语,我无法找到解释这种情况的好标题。我不知道如何在标题中解释。如果您对标题有更好的了解,可以编辑。

问题被标记为重复,但我无法通过查看给定链接中的答案来使其工作。 :(

1 个答案:

答案 0 :(得分:0)

数组构建这样的东西

        <?php   


    $new_array =array();
    foreach($array_value as $key=>$row)
    {

        if(isset($row['summonerName']))
        {

        $new_array[]=$row['summonerName'];

        }


    }

    print_r($new_array);
    ?>