1
2

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 5 years have passed since last update.

paizaで使える標準入力PHP用

Last updated at Posted at 2020-03-08

標準入力が意味不明だったのでまとめてみます。

シンプルに一行だけの場合
入力例 100

test.php
$a = trim(fgets(STDIN));
//$aに100が入る

一行でスペースまじりの場合
入力例 100 200

test.php
fscanf(STDIN,"%d %d",$a,$b);
//$aに100,$bに200が入る
//文字列の場合
fscanf(STDIN,"%s %s",$a,$b);

値を配列に入れてくパターン(二行とか)
入力例 100
    100

test.php
//空の配列を用意
$array = [];
$i=0;
while($i<=1){
//配列の後ろに一つずつ追加
    array_push($array,trim(fgets(STDIN)));
    $i++;
}
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?