How can I print this array in table form

Asked

Viewed 111 times

0

  $tabela = array(
    array("Atlético", "Goianiense", "Goiânia", "GO", "0 (não possui)"),
    array("Atlético Mineiro", "Belo Horizonte", "MG", "1 (1971)"),
    array("Atlético Paranaense", "Curitiba", "PR", "1 (2001)"),
    array("Avaí","Florianópolis", "SC", "0 (não possui)"),
    array("Bahia", "Salvador", "BA", "2 (1959, 1988) "),
    array("Botafogo", "Rio de Janeiro", "RJ", "2 (1968[TB], 1995)"),
    array("Chapecoense", "Chapecó", "SC", "0 (não possui)"),
    array("Corinthians", "São Paulo", "SP", "6 (1990, 1998, 1999, 2005, 2011, 2015)"),
    array("Coritiba", "Curitiba", "PR", "1 (1985)"),
    array("Cruzeiro", "Belo Horizonte", "MG", "4 (1966, 2003, 2013, 2014)"),
    array("Flamengo", "Rio de Janeiro", "RJ", "5 (1980, 1982, 1983, 1992, 2009)"),
    array("Fluminense", "Rio de Janeiro", "RJ", "4 (1970, 1984, 2010, 2012)"),
    array("Grêmio", "Porto Alegre", "RS", "2 (1981, 1996)"),
    array("Palmeiras", "São Paulo", "SP", "8 (1960, 1967[RGP], 1969, 1972, 1973, 1993, 1994, 2016) - Não tem MUNDIAL!"),
    array("Ponte Preta", "Campinas", "SP", "0 (não possui) "),
    array("Santos", "Santos", "SP", "8 (1961, 1962, 1963, 1964, 1965, 1968[RGP], 2002, 2004)"),
    array("São Paulo", "São Paulo", "SP", "6 (1977, 1986, 1991, 2006, 2007, 2008)"),
    array("Sport", "Recife", "PE", "1 (1987) "),
    array("Vasco da Gama", "Rio de Janeiro", "RJ", "4 (1974, 1989, 1997, 2000)"),
    array("Vitória", "Salvador", "BA", "0 (não possui)"),


  );

I’m using a foreach to go through the array array, but I don’t know how to print the rows divided into columns with each content, for example: The first column should only contain the name of the teams and the second the city and so on, but I can’t get it to print in the desired format.

  • I solved the problem with this code, but I do not know if it is the most suitable / foreach ($table as $id => $filter) { echo '<tr><td>'. $filter[0]. '</td><td>'. $filter[1]. '</td></td>'. '</td><td>'. $filter[2]. '</td>'. '</td>'. $filter[1]. '</td></tr>';

  • Wouldn’t this table have the columns? What is the origin of this data?

1 answer

0

    <?php
        $tabela = array(
            array("Atlético Goianiense", "Goiânia", "GO", "0 (não possui)"),
            array("Atlético Mineiro", "Belo Horizonte", "MG", "1 (1971)"),
            array("Atlético Paranaense", "Curitiba", "PR", "1 (2001)"),
            array("Avaí","Florianópolis", "SC", "0 (não possui)"),
            array("Bahia", "Salvador", "BA", "2 (1959, 1988) "),
            array("Botafogo", "Rio de Janeiro", "RJ", "2 (1968[TB], 1995)"),
            array("Chapecoense", "Chapecó", "SC", "0 (não possui)"),
            array("Corinthians", "São Paulo", "SP", "6 (1990, 1998, 1999, 2005, 2011, 2015)"),
            array("Coritiba", "Curitiba", "PR", "1 (1985)"),
            array("Cruzeiro", "Belo Horizonte", "MG", "4 (1966, 2003, 2013, 2014)"),
            array("Flamengo", "Rio de Janeiro", "RJ", "5 (1980, 1982, 1983, 1992, 2009)"),
            array("Fluminense", "Rio de Janeiro", "RJ", "4 (1970, 1984, 2010, 2012)"),
            array("Grêmio", "Porto Alegre", "RS", "2 (1981, 1996)"),
            array("Palmeiras", "São Paulo", "SP", "8 (1960, 1967[RGP], 1969, 1972, 1973, 1993, 1994, 2016) - Não tem MUNDIAL!"),
            array("Ponte Preta", "Campinas", "SP", "0 (não possui) "),
            array("Santos", "Santos", "SP", "8 (1961, 1962, 1963, 1964, 1965, 1968[RGP], 2002, 2004)"),
            array("São Paulo", "São Paulo", "SP", "6 (1977, 1986, 1991, 2006, 2007, 2008)"),
            array("Sport", "Recife", "PE", "1 (1987) "),
            array("Vasco da Gama", "Rio de Janeiro", "RJ", "4 (1974, 1989, 1997, 2000)"),
            array("Vitória", "Salvador", "BA", "0 (não possui)"),
          );

          echo "<table  border='1'>";
          for($i=0; $i<count($tabela);$i++){
              echo "<tr>";
              for($j=0; $j<count($tabela[$i]);$j++){
                 echo "<td>".$tabela[$i][$j]."</td>";
              }
              echo "</tr>";
          }
          echo "</table>";
    ?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.