stijn0713 Posted June 24, 2012 Share Posted June 24, 2012 I try to write a small function to print a two dimentional array but it doesn't print the value of the array, even if i use the double quotes for variable substituation? <?php function printvierkantematrix($matrix, $m, $n){ $tabel = "<table>"; for ($y = 0; $y <= $m-1; $y++){ $tabel .= "<tr>"; for ($i = 0; $i <= $n-1; $i++){ $tabel .= "<td>$matrix[$y][$i]</td>"; } $tabel .= "</tr>"; } $tabel .= "</table>"; echo $tabel; } ?> . What's wrong? Is this not a good way of printing arrays? Link to comment https://forums.phpfreaks.com/topic/264689-printing-2-dimentional-array/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 24, 2012 Share Posted June 24, 2012 Php needs to be shown where array variables start and end at inside of a double-quoted string, by surrounding the array variable in {} - $tabel .= "<td>{$matrix[$y][$i]}</td>"; Link to comment https://forums.phpfreaks.com/topic/264689-printing-2-dimentional-array/#findComment-1356595 Share on other sites More sharing options...
stijn0713 Posted June 24, 2012 Author Share Posted June 24, 2012 Ok, thanks. Sometimes those are weird decision but ok. I also got it by doing "<td>" . $matrix[$][$] . "</td>"; I guess its the same? thanks ! Link to comment https://forums.phpfreaks.com/topic/264689-printing-2-dimentional-array/#findComment-1356598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.