2016-08-08 80 views
1

我有一個這樣的數組(如下所示),我想在下面給出的圖像表格行中單獨顯示相關信息。在CodeIgniter中單獨顯示多維數組到表格行中

Array 
(
[recent_task_of_developers] => Array 
    (
     [0] => Array 
      (
       [id] => 1 
       [name] => Kazi nayem 
       [project_name] => Array 
        (
         [0] => Array 
          (
           [project_name] => Nayem Book House (BBH) 
          ) 

         [1] => Array 
          (
           [project_name] => Nayem Book House (BBH) 
          ) 

         [2] => Array 
          (
           [project_name] => Nayem Book House (BBH) 
          ) 

         [3] => Array 
          (
           [project_name] => Nayem Book House (BBH) 
          ) 

        ) 

      ) 



     [2] => Array 
      (
       [id] => 32 
       [name] => Nayem 
       [project_name] => Array 
        (
         [0] => Array 
          (
           [project_name] => Nayem - MasForce 
          ) 

         [1] => Array 
          (
           [project_name] => Nayem - MasForce 
          ) 

         [2] => Array 
          (
           [project_name] => Nayem 
          ) 

         [3] => Array 
          (
           [project_name] => Nayem Book House (BBH) 
          ) 

         [4] => Array 
          (
           [project_name] => Nayem Book House (BBH) 
          ) 

         [5] => Array 
          (
           [project_name] => Nayem - MasForce 
          ) 

         [6] => Array 
          (
           [project_name] => Nayem Book House (BBH) 
          ) 

         [7] => Array 
          (
           [project_name] => Nayem - MasForce 
          ) 

         [8] => Array 
          (
           [project_name] => Nayem - MasForce 
          ) 

         [9] => Array 
          (
           [project_name] => Nayem - MasForce 
          ) 

         [10] => Array 
          (
           [project_name] => - MasForce 
          ) 

         [11] => Array 
          (
           [project_name] => - MasForce 
          ) 

         [12] => Array 
          (
           [project_name] => - MasForce 
          ) 

         [13] => Array 
          (
           [project_name] => - MasForce 
          ) 

         [14] => Array 
          (
           [project_name] => Nayem - MasForce 
          ) 

         [15] => Array 
          (
           [project_name] => Nayem Book House (BBH) 
          ) 

         [16] => Array 
          (
           [project_name] => Nayem Book House (BBH) 
          ) 

         [17] => Array 
          (
           [project_name] => Nayem Book House (BBH) 
          ) 

         [18] => Array 
          (
           [project_name] => Nayem Book House (BBH) 
          ) 

        ) 

      ) 

我想在表格中像這張圖片一樣顯示這個數組。

enter image description here

+0

不管你做什麼不要在一列中保存多值,如CSV陣列 – Drew

+0

我看您收到的答案,而是讓你知道,我們喜歡讓海報養成展示他們所嘗試過的習慣。這是非常好的做法! – halfer

回答

1

試試這個:

foreach($recent_task_of_developers as $developers) 
{ 
    foreach($developers as $developer) 
    { 
     $id = $developer['id']; 
     $name = $developer['name']; 

     foreach($developers['project_name'] as $projects) 
     { 
      // $projects['project_name']; will contain the projects name in it 
      // put your table html accordingly 
     } 
    } 
} 

我認爲這將解決您的問題。

+0

非常感謝,現在正在工作。 。 。 – kazinayem2011

+1

太棒了:) 只需接受我的回答,並樂於助人:P –

1
foreach($recent_tasks as $tasks){ 
foreach($tasks as $task){ 
    echo $tasks['name']; // You can add style and html code here inside the string 
    foreach($task['project_name'] as $project){ 
    echo $project; 
    } 
} 
} 
+0

非常感謝,現在正在工作。 。 。 – kazinayem2011

1

試試下面代碼..

<table border="1"> 
<tr> 

<td>Name</td> 
<td>Project Name</td> 
</tr> 

<?php 
foreach($recent_task_of_developers as $developers) 
{ 
?> 
<tr> 
<?php 
    foreach($developers as $developer) 
    { 
     $id = $developer['id']; 
     $name = $developer['name']; 
?> 
<td><?php echo $name; ?></td> 

<?php 
    if (!empty($developers['project_name'])) 
    { 
      $numItems = count($developers['project_name']); // counting total projects 
      $i = 0; 
     foreach($developers['project_name'] as $projects) 
      { 
       $comma = ','; 
       if(++$i === $numItems) 
       { 
        $comma = ''; 
       } 
?> 
    <td><?php echo $projects['project_name'] . $comma ; ?></td> 
<?php 
      } 
    } 
    else 
    { 
?> 
    <td></td> 
<?php 
    } 

    } 
?> 
</tr> 
<?php 
} 
?> 

</table>