関数で値を返す場合、return文を以下のように記述します。
php
1 2return "sample"; // 「sample」という文字列を返す。 3class Calendar{ 4 private $year; 5 private $month; 6 public function __construct($y,$m){ 7 $this->year = $y; 8 $this->month = $m; 9 } 10 public function get_info(){ 11 return $this->year ."-" .$this->month; 12 } 13 private static function init_row(){ 14 $ary = array(); 15 for( $i = 0; $i <= 6; $i++ ){ 16$ary[] = "・"; 17 } 18return $ary; 19 } 20} 21 22
init_row()関数の返り値
Array ( [0] => ・ [1] => ・ [2] => ・ [3] => ・ [4] => ・ [5] => ・ [6] => ・ )となるようですが、絶望的なくらい意味がわかりません。。
return $this->year ."-" .$this->month;で年月を表示させてから、週を表示させたいから
配列を使ってるのでしょうか?
基礎から勉強したはずなのに、少し応用になっただけで、全くよくわかりません。。
どうしたらいいでしょうか?
どこで見つけたコードなのかの情報(URL)はありますか?
http://codeprep.jp/ja/editor?id=38&chapter のPHPでカレンダーを作るコースである3-4.配列への要素の追加
変数 $ary が持つ配列の末尾に 文字列「・」を追加してみましょう。にある問題です。
ログインが必須のサイトのようで、閲覧することが出来ません。