0
0

More than 3 years have passed since last update.

PHPのwhile文

Last updated at Posted at 2021-05-24

前提

PHPは未経験
PHPの学習を始めたため、アウトプットとして投稿
開発環境はXAMPP

while文の書き方

PHPのwhile文は以下のように書く

while(条件式){
    処理
}

解説すると指定した条件を満たしている場合に処理を行うという
ただそれだけ・・・

実際に書いてみた

<?php 
$i = 0;
while($i<10){
  echo $i."<br>";
  $i ++;
}
 ?>

実行結果

image.png

解説

カウンターの初期値を0としてその値が10より小さい場合にwhile文の中の処理を実行する。
処理の最後にカウンターの値を1増やす。
処理の内容は、
カウンターの値を出力する。その際に改行も行う。
出力内容は$iの値と改行になるため、
連結演算子「.」を使用して$iと改行タグを繋いだ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0