<?PHP
//
// 분기
//
$mood = "sad-";
// switch --------------------------------------
switch ($mood){
case "happy":
echo "난 행복해";
break;
case "sad":
echo "난 불행해";
break;
default:
echo "난 아무렇지 않아";
break;
}
echo "<br><br>";
// if --------------------------------------
if ($mood == "happy"){
echo "다른사람에게도 행복을 전해주세요~";
}else{
echo "행복해지려면 웃어보아요~";
}
echo "<br><br>";
// ?: --------------------------------------
echo ($mood == "happy") ? "행복바이러스~ ㅋㅋ" : "불행타파!!";
//
// 반복
//
$counter = 1;
echo "## 12까지 숫자카운트 <br>";
while ($counter <= 12){
echo ($counter++ . "/ ");
}
echo "<br>";
echo "<br>";
$counter = 1;
echo "## 12까지 숫자카운트 <br>";
do {
echo ($counter++ . "/ ");
} while ($counter <= 12);
echo "<br>";
do {
if (탈출=='ok') break;
} while (1)
for($i=1; $i<=12; $i++) {
echo "i=$i <br> \n";
}
foreach($arr as $i => $v){
echo "$i = $v <br>"; //$i = 숫자 , $v = 값
}
$arrays=array( "sample1.php", "sample11.php", "sample21.php",
"sample2.php", "sample12.php", "sample22.php",
"sample3.php", "sample13.php", "sample23.php");
natsort($arrays);
foreach ($arrays as $v)
{
print $v."<br>"; //값 출력
}
?>