phpdolan Posted October 30, 2007 Share Posted October 30, 2007 I've spent toooo many hours the last few days on this, tried many methods, read many pages.... Now requesting help. I have a multi-dimensionsal array in the form of a 6 x 10 table. I have 2 problems: 1) The foreach statement that inputs each row into a table, and 2) The php syntax in the table. First, I'm still building, so the input is in the form of a string that I 'extract' data from. There are 7 input strings in the following form: $line[0] = "00PDMIA737B3071110852006040411000000000....540351210500000000000000000"; $line[1] = "01MIAIAH092017102518068502 0165B80....0000000000002250000 0000000000000"; (Here's a snippet of my code) for ( $l=0 ; $l<=6 ; $l++ ) { if ($l == 0) { $leg[$l] = substr($line[$l],0,2); $seq_no[$l] = substr($line[$l],16,5); $total_fly[$l] = substr($line[$l],46,4); ..... } else { $leg[$l] = substr($line[$l],0,2); $dep[$l] = substr($line[$l],2,3); $dep_minutes[$l] = substr($line[$l],8,4); $dep_time[$l] = intval($dep_minutes[$l]/60) . ':' . $dep_minutes[$l] % 60 ; $arr[$l] = substr($line[$l],5,3); ...... I have confirmed that data IS in the array with a var_dump ($leg, $seq_no, $dep, ....) After converting some of the data to an hr:mn format, I've been trying to put in in different table cells with a foreach ( ) statement. Please keep in mind that the table will be 6 x 10, and I know that the code below is incorrect. for ( $leg=1 ; $leg=6 ; $leg++ ) { echo "<tr><td>".$line['leg']."</td><td>".$line['dep']."</td></tr><td>".$line['dep_time']."</td><td>".$line['arr']."</td><td>"; ..... My results are either 1) infinite loop or 2) cells with outline, but blank. Output looks correct if I only include code for the first column which is the $leg array value. Please make suggestions. I am not clear with arrays (obviously). I hope I've provided enough code. Thanks, David Link to comment https://forums.phpfreaks.com/topic/75391-arrays-and-foreach/ Share on other sites More sharing options...
kenrbnsn Posted October 30, 2007 Share Posted October 30, 2007 You don't want to be indexing into the $line variable, you want to reference the individual arrays: <?php for ($i=0;$i<6;$i++) { echo '<tr><td>' . $leg[$i] . '</td><td>' . $dep[$i] . '</td><td>' . $dep_time[$i] . '</td><td>' . $arr[$i] . '</td><td>'; }?> Ken Link to comment https://forums.phpfreaks.com/topic/75391-arrays-and-foreach/#findComment-381361 Share on other sites More sharing options...
phpdolan Posted October 30, 2007 Author Share Posted October 30, 2007 Ken, Thanks for your reply. I think I understand and will modify the code. Do I need to have a nested foreach to make the 6 rows? How might I set that up? David Link to comment https://forums.phpfreaks.com/topic/75391-arrays-and-foreach/#findComment-381399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.