-
-
Save Kazunari-h/18f815683884c6a1f8e14c5448c68627 to your computer and use it in GitHub Desktop.
ブログ用コード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 変数を宣言する | |
$name = "yamada"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 定数を宣言する (define関数) | |
define("FOO", 1); | |
// 定数を宣言する (const構文) | |
const FOO = 1; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 論理型 (boolean) | |
$is_name = true; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 整数型 (integer) | |
$count = 1; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 引用符を使った文字列型 | |
$name = 'hirosawa'; | |
// 二重引用符を使った文字列型 | |
$name = "hirosawa"; | |
// ヒアドキュメント構文を使った文字列型 (二重引用符を使ったものと機能はほぼ同じ) | |
$name = <<<EOT | |
こんにちは、 | |
hirosawaです。 | |
EOT; | |
// Nowdoc構文を使った文字列型 (引用符を使ったものと機能はほぼ同じ) | |
$name = <<<'EOT' | |
こんにちは、 | |
hirosawaです。 | |
EOT; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$name = 'hirosawa'; | |
echo "こんにちは、$name"; | |
// 結果は "こんにちは、hirosawa"と出力される | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 文字列演算子 (.) | |
$a = "Hello "; | |
$b = $a . "World!"; | |
echo $b; // Hello World! と出力されます。 | |
// 文字列演算子 (.=) | |
$a = "Hello "; | |
$a .= "World!"; | |
echo $a; // Hello World! と出力されます。 | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 配列型 (array) | |
// キーを指定しない配列 | |
$teachers = array( | |
"koizumi", | |
"hirosawa" | |
); | |
// PHP 5.4 以降ではこのようにも書けます | |
$teachers = [ | |
"koizumi", | |
"hirosawa" | |
]; | |
echo $teachers[0]; | |
// koizumi と出力されます。 | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 配列型 (array) | |
// キーを指定する配列 | |
$teachers = array( | |
"koizumi" => "rare", | |
"hirosawa" => "normal", | |
); | |
// PHP 5.4 以降ではこのようにも書けます | |
$teachers = [ | |
"koizumi" => "rare", | |
"hirosawa" => "normal", | |
]; | |
echo $teachers["koizumi"]; | |
// rare と出力されます。 | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 型を調べる | |
$name = "hirosawa"; | |
echo gettype($name); | |
// 型 (string) が出力される | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//型を変換する | |
$count_str = "10"; | |
$count = (int) $count_str; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$name = 'hirosawa'; | |
echo 'こんにちは、$name'; | |
// 結果は "こんにちは、$name"と出力される | |
// 二重引用符と同じ使い方はできない。 | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment