LoginSignup
11

More than 1 year has passed since last update.

【PHP】PHP入門

Last updated at Posted at 2020-04-23

【PHP】PHP入門

実行

Hello.php
<?php echo "Good morning"."\n";?>
<?php echo "Good evening"."\n";?>
<?php echo "Good Hello"."\n";?>
出力
Good morning
Good evening
Good Hello  

配列

Array.php
<?php
    $a = Array(8,12,21);

    echo ("朝食は".$a[0])."時です"."\n";
    echo ("昼食は".$a[1])."時です"."\n";
    echo ("夕飯は".$a[2])."時です"."\n";
出力
朝食は8時です
昼食は12時です
夕飯は21時です

条件分岐

Humidification.php
<?php
    $hum = 30;

    if ($hum >= 60) {
        echo "湿度が".$hum."%です"."\n";
        echo "ジメジメしてます"."\n";
    }else if ($hum <= 60 && $hum >=40) {
        echo "湿度が".$hum."%です"."\n";
        echo "快適です"."\n";
    }else if ($hum <= 40) {
        echo "湿度が".$hum."%です"."\n";
        echo "カラカラしてます"."\n";
    }
?>
出力
湿度が30%です
カラカラしてます

環境構築

・windowsでPHPをインストール

参考文献

・この記事は以下の情報を参考にして執筆しました。
キノコード / プログラミング学習動画のYouTuber

環境構築の追加(2022/08/09)

■下記URLより開発環境(XAMPP)をインストール
XAMPPバージョン:8.1.6

■【環境準備】XAMPPのコントロールパネルから、Webサーバー(Apache)を起動
JavaDrive - XAMPPコントロールパネルを起動する

■PHPを記述するための統合開発環境
VScode

■プラグイン
・Japanese Language Pack for VS Code
・PHP Intelephense

■計算式 (print関数で出力する場合です

calculation.php
<?php
$a = 5;
$b = 3;
$c = 2;
$d = 8;

$x = 10;
$y = 20;
$z = 7;

print($x + $y)."\n";
print($y - $z)."\n";
print($a * $b)."\n";
print($c % $a);"\n";
print($d / $b);"\n";
?>
出力
30
13
15
2
2.6666666666667

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
11