開発環境
- OS X Lion - Apple(OS)
- Apache (Web Server)
- PHP (サーバーサイドプログラミング言語)
- TextWrangler(Text Editor) (BBEditの無料機能制限版、light版)
『初めてのPHP5』 (David Sklar 著、 桑村 潤 翻訳、 廣川 類 翻訳、 オライリー・ジャパン、2005年、ISBN978-4-87311-257-2)の4章(配列の操作)4.7(演習問題)2を解いてみる。
2.
HTML、CSS、PHPのソースコード(TextWrangler)
<style> table{ table-layout:fixed; width: 250px; } .city{ width:150px; text-align:center; } .city_row{ text-align:left; } .people_row{ text-align:right; } </style> <?php $population = array( "New York, NY" => 8008278, "Los Angeles, CA" => 3694820, "Chicago, IL" => 2896016, "Houston, TX" => 1953631, "Philadelphia, PA" => 1517550, "Phoenix, AZ" => 1321045, "San Diego, CA" => 1223400, "Dallas, TX" => 1188580, "San Antonio, TX" => 1144646, "Detroit, MI" => 951270); asort($population); print '<table border=1><caption>アメリカの都市と人口(人口順)</caption>'; print '<tr><th class="city">都市</th><th class="people">人口</th></tr>'; $total = 0; foreach($population as $city => $people){ print '<tr><td class="city_row">' . $city . '</td><td class="people_row">' . $people . '</td></tr>'; $total += $people; } print '<tr><td class="city">合計</td><td class="people_row"> ' . $total . '</td></tr></table>'; ksort($population); print '<table border=1><caption>アメリカの都市と人口(都市名順)</caption>'; print '<tr><th class="city">都市</th><th class="people">人口</th></tr>'; foreach($population as $city => $people){ print '<tr><td class="city_row">' . $city . '</td><td class="people_row">' . $people . '</td></tr>'; } print '<tr><td class="city">合計</td><td class="people_row"> ' . $total . '</td></tr></table>'; ?>
0 コメント:
コメントを投稿