0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHP 標準入力の方法

Last updated at Posted at 2021-03-15

#標準入力の方法

1行の場合


$one = trim(fgets(STDIN));
var_dump($one);

複数行の場合


<?php

while ($line = fgets(STDIN)) {
    // 配列を生成
    $arr[] = trim($line);
}
   var_dump($arr);

   結果
    /*
    arr(2) {
  [0]=>
  string(2) "60"
  [1]=>
  string(2) "90"
}
*/

trim()で囲っているのは余分な改行や余白をなくす為にしようしている(必ず必要なものではない)

0
0
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?