WordPressを学ぶための初めてのPHP。
今回は、「変数」について。
目次
PHPの変数の基本の記述「$」

$の後には、好きな言葉(アルファベット、数字、アンダースコア(_))を入れるにゃん
※NGは、先頭が数字や特殊文字の入った変数は無効になる
PHPの変数の基本の記述「$」
「$」+「テキスト」+「=」+「代入テキスト」+「;」でセットされます。
<?php
$var = 'やっほー';
?>
ブラウザ表示結果
なし
ブラウザに表示させるには、echo
変数をエコーします。
<?php
$neko = 'やっほー';
echo $neko;
?>



変数には「’」をつけれない。「”」はつけれるよ。
ブラウザ表示結果
やっほー
変数は、ダブルコーテーションもしくは、何もなし
変数の書き出しはダブルコーテーション(”)か、何もなしでechoできる。(シングルコーテーションは✖️)
<?php
$neko = 'やっほー';
echo $neko"<br>";
echo "$neko";
?>
ブラウザ表示結果
やっほー
やっほー
「.」文字列演算子
「.」は、変数や文字列などを繋げるマークです。
<?php
$esa = 'えさ';
$kure = 'くれ';
echo $esa.$kure.'にゃん';
?>



変数も文字列もつながるにゃん
ブラウザ表示結果
えさくれにゃん