0
0

【PHP】 paizaスキルチェック 文字の一致 解答

Last updated at Posted at 2024-05-12

問題はこちら

解答

answer.php
<?php
    //文字列を代入
    $a = trim(fgets(STDIN));
    $b = trim(fgets(STDIN));
    
    //$a, $bの比較
    if ($a === $b) {
        echo 'OK';
    }else {
        echo 'NG';
    }
?>

Point

今回は特に特筆すべき点はありませんが、文字列という指定がありましたので、==ではなく===を利用しています。PHPにおいて、==は型の比較がなく、===では型の一致も確認されます。比較演算子に関する詳しい内容は以下マニュアルからどうぞ。

参照

https://paiza.jp/works/mondai/d_rank_skillcheck_sample/diff_str
PHPの比較演算子について
https://www.php.net/manual/ja/language.operators.comparison.php

0
0
1

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