kuku.php
「../libs/Smarty.class.php」のパスは環境に合わせて調整が必要です。
<?php
/**
* Smarty問題
* 九々
* kuku.php - kuku.tpl
* @package smarty_lesson
* @author
* @since
*/
for ( $i = 1; $i <= 9; $i ++){
for ( $j = 1; $j <= 9; $j ++){
//2次元配列の作成
$num[$i][] = $i*$j;
}
}
require( "../libs/Smarty.class.php" );
$smarty = new Smarty();
$smarty -> assign( "num", $num );
$smarty -> display( "kuku.tpl" );
kuku.tpl
<html>
<body>
<table border = "1">
<caption>【九九の表】</caption>
<tr><th width="30"><br></th>
{for $j=1 to 9}
<th width="70">
{$j}
</th>
{/for}
</tr>
{{foreach $num as $key1=>$row}}
<tr>
<th>{$key1}</th>
{{foreach $row as $key2=>$col}}
<td align=center>{$key1}*{$key2+1} = {$col}</td>
{/foreach}
</tr>
{/foreach}
</table>
</body>
</html>
私たちのクラスでは行いませんでした。
返信削除参考にさせて頂きます、ありがとう。