2017-02-17 17 views
-1

私は調査を表示するために使用される2次元配列を持っています。配列には63行(質問)が含まれています。各行には、GpDesc(グループ化リーダーシップの特性)とQueDesc(質問)が含まれています。 9種類のGpDescがあります。最初の発生時にGpDescをエコーし​​、そのグループ内の質問とラジオボタンを次のGpDescまでエコーしたいと思います。私は、GpDescの数とそのグループ内の質問のための内部ループの外側のループが必要だが、私はこれを行う方法がわからないことを知っている。 $ varArrayの一部です:2次元配列のエコー値

Array ( 
    [0] => Array ( 
     [GpID] => 1168 
     [GpDesc] => LEADERSHIP TRAITS 
     [QueID] => 10266 
     [QueDesc] => Is visionary 
     [GpQue] => 0 
    ) 
    [1] => Array ( 
     [GpID] => 1168 
     [GpDesc] => LEADERSHIP TRAITS 
     [QueID] => 10267 
     [QueDesc] => Possesses high degree of integrity 
     [GpQue] => 0 
    ) 
    [2] => Array ( 
     [GpID] => 1168 
     [GpDesc] => LEADERSHIP TRAITS 
     [QueID] => 10268 
     [QueDesc] => Displays an enthusiastic, positive outlook 
     [GpQue] => 0 
    ) 
    [3] => Array ( 
     [GpID] => 1168 
     [GpDesc] => LEADERSHIP TRAITS 
     [QueID] => 10269 
     [QueDesc] => Uses good executive judgment 
     [GpQue] => 0 
    ) 
    [4] => Array ( 
     [GpID] => 1168 
     [GpDesc] => LEADERSHIP TRAITS 
     [QueID] => 10270 
     [QueDesc] => Provides effective leadership 
     [GpQue] => 0 
    ) 
    [5] => Array ( 
     [GpID] => 1168 
     [GpDesc] => LEADERSHIP TRAITS 
     [QueID] => 10271 
     [QueDesc] => Organizes and administers in a confident manner 
     [GpQue] => 0 
    ) 
    [6] => Array ( 
     [GpID] => 1168 
     [GpDesc] => LEADERSHIP TRAITS 
     [QueID] => 10272 
     [QueDesc] => Acts fairly and decisively on important issues 
     [GpQue] => 0 
    ) 
    [7] => Array ( 
     [GpID] => 1168 
     [GpDesc] => LEADERSHIP TRAITS 
     [QueID] => 10273 
     [QueDesc] => Displays effective strategic planning 
     [GpQue] => 0 
    ) 
    [8] => Array ( 
     [GpID] => 1168 
     [GpDesc] => LEADERSHIP TRAITS 
     [QueID] => 10274 
     [QueDesc] => Establishes appropriate goals and objectives 
     [GpQue] => 0 
    ) 
    [9] => Array ( 
     [GpID] => 1168 
     [GpDesc] => LEADERSHIP TRAITS 
     [QueID] => 10275 
     [QueDesc] => Defines appropriate priorities 
     [GpQue] => 0 
    ) 
    [10] => Array ( 
     [GpID] => 1168 
     [GpDesc] => LEADERSHIP TRAITS 
     [QueID] => 10276 
     [QueDesc] => Entertains new ideas 
     [GpQue] => 0 
    ) 
    [11] => Array ( 
     [GpID] => 1169 
     [GpDesc] => MANAGEMENT TRAITS 
     [QueID] => 10277 
     [QueDesc] => Involves faculty in strategic planning 
     [GpQue] => 0 
    ) 
    [12] => Array ( 
     [GpID] => 1169 
     [GpDesc] => MANAGEMENT TRAITS 
     [QueID] => 10278 
     [QueDesc] => Utilizes departmental advisory group or other clientele in decision making 
     [GpQue] => 0 
    ) 
    [13] => Array ( 
     [GpID] => 1169 
     [GpDesc] => 

誰かが助けてくれますか?

+1

あなたは 'ますprint_r($配列)の結果とそのダンプを置き換えることができます;'や混乱について – RiggsFolly

+0

申し訳ありませんが、それの少なくとも数occurancesが、ここではその一部です。 – AKAllen

+0

[多次元配列を出力できません]の複製があります(http://stackoverflow.com/questions/31702980/cannot-output-multi-dimensional-array) –

答えて

1
<?php 
$survey = 
Array(
       Array (
         'GpID' => 1168, 
         'GpDesc' => 'LEADERSHIP TRAITS', 
         'QueID' => 10266, 
         'QueDesc' => 'Is visionary', 
         'GpQue' => 0 
        ), 
       Array (
         'GpID' => 1168, 
         'GpDesc' => 'LEADERSHIP TRAITS', 
         'QueID' => 10267, 
         'QueDesc' => 'Possesses high degree of integrity', 
         'GpQue' => 0 
        ), 
       Array (
         'GpID' => 1169, 
         'GpDesc' => 'MANAGEMENT TRAITS', 
         'QueID' => 10277, 
         'QueDesc' => 'Involves faculty in strategic planning', 
         'GpQue' => 0 
        ), 
       Array (
         'GpID' => 1169, 
         'GpDesc' => 'MANAGEMENT TRAITS', 
         'QueID' => 10278, 
         'QueDesc' => 'Utilizes departmental advisory group or other clientele in decision making', 
         'GpQue' => 0 
        ) 
       ); 

echo $survey[0]['GpDesc'].PHP_EOL; 
$prevGpId = $survey[0]['GpID']; 

foreach ($survey as $line) { 
     if ($line['GpID'] !== $prevGpId) { 
       echo $line['GpDesc'].PHP_EOL; 
       $prevGpId = $line['GpID']; 
     } 
     echo "\t".$line['QueDesc'].PHP_EOL; 
} 
+0

ありがとうございました!それがまさに私が必要としていたものです。 – AKAllen