0

How to print array data in table format with appropriate table head and data. Or in DIV also

<!DOCTYPE html>
<html>
<head>
    <title>Array</title>
</head>
<body>

<?php
    $arr = array
  (
  array("U Jadeja",100,100),
  array("A Dave",200,200),
  array("K Lathiya",300,300),
  array("A Kanani",400,400),
  array("Brock lesnar",400,400),
  );
?>

<


</body>
</html>

1 Answer 1

1

It works...

<!DOCTYPE html>
<html>
<head>
    <title>Array</title>
</head>
<body>

<?php
    $arr = array
  (
  array("Upendrasinh",100,100),
  array("Ankit dave",200,200),
  array("Krunal Lathiya",300,300),
  array("Arjun Kanani",400,400),
  );

  $arrCount = count($arr);


  // $arrsubcount = count($arr[0]);
  // echo $arrsubcount;
  // echo "<br>";

  $arraycell=count($arr[0][0]);
  $arraycell=$arraycell;

echo '<table border="5px" width="100%">';
        echo "<tr>";
            echo "<th>Name</th>";
            echo "<th>Score</th>";
            echo "<th>Score2</th>";
        echo "</tr>";
  for($arrayrow=0;$arrayrow<=$arrCount-1;$arrayrow++){
            echo "<tr>"."<td>".$arr[$arrayrow][0]. "</td>"; 
                for($arraycolumn=0;$arraycolumn<$arraycell;$arraycolumn++){
                    echo "<td>".$arr[$arrayrow][$arraycell]."</td>";
                    echo "<td>".$arr[$arrayrow][$arraycell+1]."</td>"."</tr>";
                }
    }
  echo '</table>';

?>

</body>
</html>
4
  • So you answered your own question?
    – DirtyBit
    Dec 3, 2015 at 12:56
  • 2
    but you answered moments after asking question .. looks like you were already ready with question and the answer.
    – Guanxi
    Dec 3, 2015 at 13:23
  • 2
    @user5173426, Self answers are encouraged. Do not berate a user for doing exactly what we ask them to do. The option to answer the question appears immediately under the "Post Question" button.
    – Andy
    Dec 3, 2015 at 15:34
  • @Guanxi Please see the above comment, and understand that self answered questions are encouraged
    – Andy
    Dec 3, 2015 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.