開発環境
- OS X Lion - Apple(OS)
- Apache (Web Server)
- PHP (サーバーサイドプログラミング言語)
- MySQL (データベース)
- TextWrangler(Text Editor) (BBEditの無料機能制限版、light版)
『初めてのPHP & MySQL 第2版』(Michele E. Davis、Jon A. Phillips 著、西沢 直木 訳、オライリー・ジャパン、2008年、ISBN978-4-87311-365-4)の6章(配列)の問題を解いてみる。
問6-1.
数値インデックスの配列の最初の要素のインデックスは0。
問6-2, 3, 4.
コード(TextWrangler)
<html> <head> <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'/> <title></title> </head> <body> <?php $lang[] = 'php'; $lang[] = 'javascript'; $lang[] = 'C#'; echo "$lang[0]<br /><br />"; $months = array('January','February','March','April', 'May','June','July','August', 'September','October','November','December'); $days = array(31,28,31,30,31,30,31,31,30,31,30,31); $months_and_days = array(); for($i = 0 ; $i < count($months); $i++){ $months_and_days[$months[$i]] = $days[$i]; } $ary = array($months,$days,$months_and_days); foreach($ary as $value){ var_dump($value); echo "<br /><br />"; } foreach($ary as $a){ while(list ($key,$value) = each($a)){ echo "$key => $value<br />"; } echo "<br />"; } ?> </body> </html>ß
出力結果(ブラウザ)
php array(12) { [0]=> string(7) "January" [1]=> string(8) "February" [2]=> string(5) "March" [3]=> string(5) "April" [4]=> string(3) "May" [5]=> string(4) "June" [6]=> string(4) "July" [7]=> string(6) "August" [8]=> string(9) "September" [9]=> string(7) "October" [10]=> string(8) "November" [11]=> string(8) "December" } array(12) { [0]=> int(31) [1]=> int(28) [2]=> int(31) [3]=> int(30) [4]=> int(31) [5]=> int(30) [6]=> int(31) [7]=> int(31) [8]=> int(30) [9]=> int(31) [10]=> int(30) [11]=> int(31) } array(12) { ["January"]=> int(31) ["February"]=> int(28) ["March"]=> int(31) ["April"]=> int(30) ["May"]=> int(31) ["June"]=> int(30) ["July"]=> int(31) ["August"]=> int(31) ["September"]=> int(30) ["October"]=> int(31) ["November"]=> int(30) ["December"]=> int(31) } 0 => January 1 => February 2 => March 3 => April 4 => May 5 => June 6 => July 7 => August 8 => September 9 => October 10 => November 11 => December 0 => 31 1 => 28 2 => 31 3 => 30 4 => 31 5 => 30 6 => 31 7 => 31 8 => 30 9 => 31 10 => 30 11 => 31 January => 31 February => 28 March => 31 April => 30 May => 31 June => 30 July => 31 August => 31 September => 30 October => 31 November => 30 December => 31
HTMLソース
<html> <head> <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'/> <title></title> </head> <body> php<br /><br />array(12) { [0]=> string(7) "January" [1]=> string(8) "February" [2]=> string(5) "March" [3]=> string(5) "April" [4]=> string(3) "May" [5]=> string(4) "June" [6]=> string(4) "July" [7]=> string(6) "August" [8]=> string(9) "September" [9]=> string(7) "October" [10]=> string(8) "November" [11]=> string(8) "December" } <br /><br />array(12) { [0]=> int(31) [1]=> int(28) [2]=> int(31) [3]=> int(30) [4]=> int(31) [5]=> int(30) [6]=> int(31) [7]=> int(31) [8]=> int(30) [9]=> int(31) [10]=> int(30) [11]=> int(31) } <br /><br />array(12) { ["January"]=> int(31) ["February"]=> int(28) ["March"]=> int(31) ["April"]=> int(30) ["May"]=> int(31) ["June"]=> int(30) ["July"]=> int(31) ["August"]=> int(31) ["September"]=> int(30) ["October"]=> int(31) ["November"]=> int(30) ["December"]=> int(31) } <br /><br />0 => January<br />1 => February<br />2 => March<br />3 => April<br />4 => May<br />5 => June<br />6 => July<br />7 => August<br />8 => September<br />9 => October<br />10 => November<br />11 => December<br /><br />0 => 31<br />1 => 28<br />2 => 31<br />3 => 30<br />4 => 31<br />5 => 30<br />6 => 31<br />7 => 31<br />8 => 30<br />9 => 31<br />10 => 30<br />11 => 31<br /><br />January => 31<br />February => 28<br />March => 31<br />April => 30<br />May => 31<br />June => 30<br />July => 31<br />August => 31<br />September => 30<br />October => 31<br />November => 30<br />December => 31<br /><br /> </body> </html>
併せて読んでいる書籍。
Pythonの学習が1周したら上記の2冊を順に取り組む計画。それまではひたすら復習!
0 コメント:
コメントを投稿