開発環境
- OS X El Capitan - Apple (OS)
- Emacs (Text Editor)
- PHP 7.0 (プログラミング言語)
Learning PHP: A Gentle Introduction to the Web's Most Popular Language (David Sklar (著)、 O'Reilly Media)のChapter 4.(Groups of Data: Working with Arrays)のExercises 1.(No. 2068)を取り組んでみる。
Exercises 1.(No. 2068)
コード(Emacs)
$locations_and_populations = array('New York, NY' => 8175133,
'Los Angeles, CA' => 3792621,
'Chicago, IL' => 2695598,
'HOuston, TX' => 2100263,
'Philadelphia, PA' => 1526006,
'Phoenix, AZ' => 1445632,
'San Antonio, TX' => 1327407,
'San Diego, CA' => 1307402,
'Dallas, TX' => 1197816,
'San Jose, CA' => 945942);
$total = 0;
foreach ($locations_and_populations as $location => $population) {
print $location . ': ' . $population . "\n";
$total += $population;
}
print 'total: ' . $total . "\n";
入出力結果(Terminal, Interactive shell)
$ php70 -a < sample1.php Interactive shell New York, NY: 8175133 Los Angeles, CA: 3792621 Chicago, IL: 2695598 HOuston, TX: 2100263 Philadelphia, PA: 1526006 Phoenix, AZ: 1445632 San Antonio, TX: 1327407 San Diego, CA: 1307402 Dallas, TX: 1197816 San Jose, CA: 945942 total: 24513820 $
0 コメント:
コメントを投稿