<?php
defined('BASEPATH') OR exit('No direct script access allowed');

function print_array($array)
{
  $text = '';
  foreach ($array as $key => $value)
  { 
    if(count($array[$key]) < 2 )
    { 
      $text .= $key.'= '.$array[$key].'<br>';
    } 
    else
    {
      $array_2 = $array[$key];

      foreach ($array_2 as $key_2 => $value_2)
      {
        if(count($array_2[$key_2]) < 2 )
        { 
          $text .= '- '.$key_2.': '.$array_2[$key_2].'<br>'; 
        } 
        else 
        {
          $array_3 = $array_2[$key_2];
          foreach ($array_3 as $key_3 => $value_3)
          {
            if(count($array_3[$key_3]) < 2 )
            { 
              $text .= '--'.$key_3.': '. $array_3[$key_3].'<br>'; 
            } 
            else
            {
              $array_4 = $array_3[$key_3];
              foreach ($array_4 as $key_4 => $value_4)
              {
                if(count($array_4[$key_4]) < 2 )
                { 
                  $text .= '---'.$key_4.': '. $array_4[$key_4].'<br>'; 
                } 
              }
            }
          }
        }           
      }      
    }
  }

  return($text);
}
?>

<div class="table-responsive">
    <table id="example1" class="table table-bordered table-striped">
      <thead>
        <tr>
          <?php $th = array(); $urut = 0;  foreach ($data['result']['list'][0] as $key => $value){ ?>
            <th><?php $th[$urut] = ''.$key.''; $urut++; echo $key ?></th>
          <?php } ?>
        </tr>
      </thead>
      <tbody>
        <?php 
        $urut = 0; foreach ($data['result']['list'] as $key){?>
            <?php foreach ($th as $key_utama) { 
              ?>
              <!-- <td><?php echo count($key[$key_utama]) ?></td> -->
              <td><?php if(isset($key[$key_utama])){ if(count($key[$key_utama]) < 2){ echo $key[$key_utama]; } else echo print_array($key[$key_utama]); } else echo '-'; ?></td>
            <?php } ?>
          </tr>
        <?php } ?>
      </tbody>
    </table>
</div>

<script>   
  $(document).ready(function(){
    $('#example1').DataTable({
      "paging": true,
      "lengthChange": true,
      "searching": true,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": false,
    });
  });
</script>

