0

私がしたいこと

ここにメイン配列があります

   Array
    (
        [0] => Array
            (
                [Culture] => Array
                    (
                        [id] => 8
                        [title] => test123
                        [description] => test123
                        [year] => 2012
                        [photo] => test123.JPG                        
                        [datetime] => 0000-00-00 00:00:00
                        [status] => 0
                    )

            )

        [1] => Array
            (
                [Culture] => Array
                    (
                        [id] => 9
                        [title] => here title
                        [description] => here title
                        [year] => 2012
                        [photo] => here.JPG                        
                        [datetime] => 0000-00-00 00:00:00
                        [status] => 0
                    )

            )

        [2] => Array
            (
                [Culture] => Array
                    (
                        [id] => 11
                        [title] => here title 2
                        [description] => here title 2
                        [year] => 2012
                        [photo] => here.JPG                        
                        [datetime] => 0000-00-00 00:00:00
                        [status] => 0
                    )

            )

        [3] => Array
            (
                [Culture] => Array
                    (
                        [id] => 12
                        [title] => here title 3
                        [description] => here title 3
                        [year] => 2013
                        [photo] => here.JPG                        
                        [datetime] => 0000-00-00 00:00:00
                        [status] => 0
                    )

            )

        [4] => Array
            (
                [Culture] => Array
                    (
                        [id] => 13
                        [title] => here title 4
                        [description] => here title 4
                        [year] => 2014
                        [photo] => here.JPG                        
                        [datetime] => 0000-00-00 00:00:00
                        [status] => 0
                    )

            )

        [5] => Array
            (
                [Culture] => Array
                    (
                        [id] => 14
                        [title] => here title 5
                        [description] => here title 5
                        [year] => 2015
                        [photo] => here.JPG                        
                        [datetime] => 0000-00-00 00:00:00
                        [status] => 0
                    )

            )               
    )

この配列から、次のような(キーごとの)年の配列が必要です。

Array
(
[0]=>2012
[1]=>2013
[2]=>2014
[3]=>2015
)
4

5 に答える 5

1

私のやり方は、無名関数を使用して配列を埋めるarray-walkを使用することです。解決策は 1 行のコードで済みます。

于 2013-10-07T07:24:36.430 に答える
0

それは私のために働いています

    foreach($cultures as $row)
    {
        $year[]=$row['Culture']['year'];
    }
    $year = array_unique($year);
    $year = array_values($year);
    echo "<pre>";print_r($year);
于 2013-10-07T06:56:45.590 に答える