添字と繰り返し文
<?php $product[0] = '鉛筆'; $product[1] = '消しゴム'; $product[2] = '定規'; $product[3] = 'コンパス'; $product[4] = 'ボールペン'; ?> <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>foreach文で添字を出力する</title> </head> <body> <table border="1" width="160"> <tr><th>番号</th><th>商品名</th></tr> <?php foreach($product as $id => $value){ print'<tr><td>'.$id.'</td><td>'.$value.'</td></tr>'."\n"; } ?> </table> </body> </html>