Jump to content

[SOLVED] How to create a table with for loop


erdomester

Recommended Posts

Hi everyone,

I would like to create a table from three arrays. These are:

 

$Size: 35,38,42

$Title: S,M,L

$Price: 200,210,230

 

I want it to look like this:

 

Size    Title    Price

35        S        200

38        M      210

42        L        230

 

I've been trying for hrs now but without luck.

 

 

This assumes that the arrays are the same size and in the right order relative to each other

<?php
$Size = array(35, 38, 42);
$Title = array('S', 'M', 'L');
$Price = array(200, 210, 230);

echo '<table><tr><td>Size</td><td>Title</td><td>Price</td></tr>';

for ($i = 0; $i<sizeof($Size); $i++) {
  echo '<tr><td>' . $Size[$i] . '</td><td>' . $Title[$i] . '</td><td>' . $Price[$i] . '</td><td></tr>';
}

echo '</table>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.