PHP
WHILE, FOR, FOREACH in PHP
HiroDaegu
2022. 1. 2. 20:08
728x90
SMALL
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WEB</title>
</head>
<style>
* {
text-align: center;
}
</style>
<body>
<h1>WHILE IN PHP</h1>
<p>조건식의 결과가 TRUE이면 처리를 실행, FALSE면 반복을 그만</p>
<p>while(조건식) {처리1; 처리2; ...}</p>
<pre>
$i = 0;
while($i <= 10) {
print $i++;
print "BR";
}
</pre>
<?php
$i = 0;
while($i <= 10) {
print $i."번째 숫자 = ".$i++;
print "<BR>";
}
?>
<h1>FOR IN PHP</h1>
<pre>
for($j = 0; $j < 10; $j++) {
print $j++;
print "BR";
}
</pre>
<?php
for($j = 0; $j < 10; $j++ ) {
print $j."번재 숫자 = ". $j;
print "<BR>";
}
?>
<h1>FOREACH IN PHP</h1>
<?php
$member = array("name" => "○철수", "age" => 30, "tall" => 180);
foreach($member as $key => $value) {
if($key == "name") {
$title = "이름";
} else if($key == "age"){
$title = "연령";
}else if($key == "tall"){
$title = "신장";
}
print "$title : $value";
print "<BR>";
}
?>
</body>
</html>
728x90
LIST