<html>
<head><title>PHP Sample 3</title></head>
<body>
<h3>PHP Sample 3</h3>
<h4>if文のサンプル</h4>
<?php
$time = date( "G" );
print "今は $time 時です.";
if( $time<11 ){
print "おはよう";
}elseif( $time<18 ){
print "こんにちわ";
}else{
print "こんばんわ";
}
?>
<h4>for文のサンプル</h4>
<?php
for( $i=1 ; $i<=10 ; $i++ ){
printf( "羊が%d匹 ", $i );
}
?>
<h4>while文のサンプル</h4>
<?php
$i = 1;
while( $i<=10 ){
print "羊が" . $i . "匹 ";
$i = $i + 1;
}
?>
<h4>配列とforeach文のサンプル</h4>
<?php
$kind = array( "コーヒー", "紅茶", "緑茶", "ジュース", "炭酸飲料", "その他" );
print "飲物を ";
foreach( $kind as $nomimono){
print "$nomimono ";
}
print "の中から選んでください";
?>
</body>
</html>