Advertisement
LucianoCharles2017

ARRAY_EM_TABELAS

Oct 3rd, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2. $array = [
  3.     "posicao" => [0],
  4.     "nome" => ['nome1', 'nome2', 'nome3', 'nome4', 'nome5', 'nome6'],
  5.     "variacao" => [10, 20]
  6. ];
  7. $t = null;
  8. /**
  9. *PRECISO SABER QUAL DOS INDICES TEM MAIS VALUES
  10. * ASSIM POSSO FAZER O FOR PELO MAIOR VALOR
  11. */
  12. foreach ($array as $a) {
  13.     $t[] = count($a);
  14. }
  15. $total = max($t);
  16. ?>
  17.  
  18. <table class="table table-striped">
  19.     <thead>
  20.         <tr>
  21.             <th>Posição</th>
  22.             <th>Nome</th>
  23.             <th>Variação</th>
  24.         </tr>
  25.     </thead>
  26.     <tbody>
  27.         <?php
  28.         for ($p = 0; $p <= $total; $p++) {
  29.             echo "<tr>";
  30.             echo (isset($array['posicao'][$p])) ? "<td>{$array['posicao'][$p]}</td>" : "<td></td>";
  31.             echo (isset($array['nome'][$p])) ? "<td>{$array['nome'][$p]}</td>" : "<td></td>";
  32.             echo (isset($array['variacao'][$p])) ? "<td>{$array['variacao'][$p]}</td>" : "<td></td>";
  33.             echo "</tr>";
  34.         }
  35.         ?>
  36.     </tbody>
  37. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement