while은 반복문이다.
while 예시와 설명
<?
$i = 0; //i라는 함수를 지정함
while ($i <4) { //반복문을 지정하고, 가로에 있는 것은 i라는 함수를 4번 돌리라는 것. while이 6행의 가로까지 가면, 다시 이 행으로 돌아와 실행이 되며, 4까지 오면 멈춘다.
echo '7<br>'; // 7을 출력하라
$i = $i + 1; //i에 1을 더해라
}
?>
while 활용 총 코드
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>while</title>
</head>
<body>
<h1>while</h1>
<?php
echo '1<br>';
$i = 0;
while($i < 4) {
echo '7<br/>';
$i = $i + 1;
}
echo '3<br>';
?>
</body>
</html>
댓글