Php阵列显示表

时间:2014-04-10 03:16:51

标签: php arrays

我有一些数组

    Array
(
    [Position] => Array
        (
            [0] => Array
                (
                    [question_summary] => 
                )

            [1] => Array
                (
                    [question_summary] => 
                )

            [2] => Array
                (
                    [question_summary] => 
                )

            [3] => Array
                (
                    [question_summary] => 
                )

            [4] => Array
                (
                    [question_summary] => 
                )

        )

    [Resources, Systems & Equipment] => Array
        (
            [0] => Array
                (
                    [question_summary] => 
                )

            [1] => Array
                (
                    [question_summary] => 
                )

            [2] => Array
                (
                    [question_summary] => 
                )

            [3] => Array
                (
                    [question_summary] => 
                )

        )

    [Security & Safety] => Array
        (
            [0] => Array
                (
                    [question_summary] => 
                )

            [1] => Array
                (
                    [question_summary] => 
                )

            [2] => Array
                (
                    [question_summary] => 
                )

            [3] => Array
                (
                    [question_summary] => 
                )

        )

    [Rewards & Recognition] => Array
        (
            [0] => Array
                (
                    [question_summary] => 
                )

            [1] => Array
                (
                    [question_summary] => 

                )

            [2] => Array
                (
                    [question_summary] => 

                )

            [3] => Array
                (
                    [question_summary] => 

                )

            [4] => Array
                (
                    [question_summary] => 

                )

        )

    [Capability] => Array
        (
            [0] => Array
                (
                    [question_summary] => 

                )

            [1] => Array
                (
                    [question_summary] => 

                )

            [2] => Array
                (
                    [question_summary] => 

                )

            [3] => Array
                (
                    [question_summary] => 

                )

            [4] => Array
                (
                    [question_summary] => 

                )

        )

    [Achievement] => Array
        (
            [0] => Array
                (
                    [question_summary] => 

                )

            [1] => Array
                (
                    [question_summary] => 

                )

            [2] => Array
                (
                    [question_summary] => 

                )

            [3] => Array
                (
                    [question_summary] => 

                )

            [4] => Array
                (
                    [question_summary] => 

                )

        )

    [Growth & Development] => Array
        (
            [0] => Array
                (
                    [question_summary] => 

                )

            [1] => Array
                (
                    [question_summary] => 

                )

            [2] => Array
                (
                    [question_summary] => 

                )

            [3] => Array
                (
                    [question_summary] => 

                )

        )

    [Balance] => Array
        (
            [0] => Array
                (
                    [question_summary] => 

                )

            [1] => Array
                (
                    [question_summary] => 

                )

            [2] => Array
                (
                    [question_summary] => 

                )

            [3] => Array
                (
                    [question_summary] => 

                )

            [4] => Array
                (
                    [question_summary] => 

                )

            [5] => Array
                (
                    [question_summary] => 

                )

        )

    [Colleagues] => Array
        (
            [0] => Array
                (
                    [question_summary] => 

                )

            [1] => Array
                (
                    [question_summary] => 

                )

            [2] => Array
                (
                    [question_summary] => 

                )

            [3] => Array
                (
                    [question_summary] => 

                )

        )

    [Manager] => Array
        (
            [0] => Array
                (
                    [question_summary] => 

                )

            [1] => Array
                (
                    [question_summary] => 

                )

            [2] => Array
                (
                    [question_summary] => 

                )

            [3] => Array
                (
                    [question_summary] => 

                )

            [4] => Array
                (
                    [question_summary] => 

                )

            [5] => Array
                (
                    [question_summary] => 

                )

            [6] => Array
                (
                    [question_summary] => 

                )

            [7] => Array
                (
                    [question_summary] => 

                )

        )

    [Senior Leadership] => Array
        (
            [0] => Array
                (
                    [question_summary] => 

                )

            [1] => Array
                (
                    [question_summary] => 

                )

            [2] => Array
                (
                    [question_summary] => 

                )

            [3] => Array
                (
                    [question_summary] => 

                )

            [4] => Array
                (
                    [question_summary] => 

                )

            [5] => Array
                (
                    [question_summary] => 

                )

            [6] => Array
                (
                    [question_summary] => 

                )

        )

    [Organisation] => Array
        (
            [0] => Array
                (
                    [question_summary] => 

                )

            [1] => Array
                (
                    [question_summary] => 

                )

            [2] => Array
                (
                    [question_summary] => 

                )

            [3] => Array
                (
                    [question_summary] => 

                )

            [4] => Array
                (
                    [question_summary] => 

                )

            [5] => Array
                (
                    [question_summary] => 

                )

            [6] => Array
                (
                    [question_summary] => 

                )

        )

)

然后我有一个包含3列的“表格”

如何让我的阵列成为
     |职位|能力|同事|
     |资源|成就|经理|
     |安全|成长|高级|
     |奖励|平衡|组织|

感谢名单

1 个答案:

答案 0 :(得分:0)

你应该使用一些%(模数)-magic:

$array = array(1,2,3,4,5,6,7,8,9);

$numColumns = 3;
$newArray = array_fill(0, $numColumns, array());
for($i = 0; $i < count($array); $i++){
    $newArray[$i%$numColumns][floor($i/$numColumns)] = $array[$i];
}

print_r($newArray);

请参阅this PHP-Fiddle