비전공자 개발일기

WHILE, FOR, FOREACH in PHP 본문

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

'PHP' 카테고리의 다른 글

PHP imagecreatefrompng / ImageColorAllocate / ImageTTFText  (0) 2022.02.22
Function with PHP (변수)  (0) 2022.01.03
SWITCH CASE with PHP  (0) 2022.01.01
PHP with if condition  (0) 2021.12.31
PHP with Select Option  (0) 2021.12.30