From b8784faf28ffcda0bc8b5a122a7845ebc6b3432d Mon Sep 17 00:00:00 2001 From: Tomy Date: Sun, 17 Jan 2016 13:04:25 +0900 Subject: translate to 487 --- ja-jp/php.html.markdown | 64 +++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 31 deletions(-) (limited to 'ja-jp') diff --git a/ja-jp/php.html.markdown b/ja-jp/php.html.markdown index 22c0561c..96d45f08 100644 --- a/ja-jp/php.html.markdown +++ b/ja-jp/php.html.markdown @@ -328,7 +328,7 @@ switch ($x) { //デフォルトで何かを実行します } -// While, do...while and for loops are probably familiar +// while, do, forの構文は、おそらく他の言語とも共通なものです $i = 0; while ($i < 5) { echo $i++; @@ -351,14 +351,14 @@ echo "\n"; $wheels = ['bicycle' => 2, 'car' => 4]; -// Foreach loops can iterate over arrays +//Foreachループによって、 配列を反復処理できます foreach ($wheels as $wheel_count) { echo $wheel_count; } // Prints "24" echo "\n"; -// You can iterate over the keys as well as the values +// 値と同じ様に、keyも反復処理できます foreach ($wheels as $vehicle => $wheel_count) { echo "A $vehicle has $wheel_count wheels"; } @@ -382,20 +382,20 @@ for ($i = 0; $i < 5; $i++) { /******************************** - * Functions + * 関数 */ -// Define a function with "function": +// 関数を"function"で定義します function my_function () { return 'Hello'; } echo my_function(); // => "Hello" -// A valid function name starts with a letter or underscore, followed by any -// number of letters, numbers, or underscores. +// 有効な関数名は、文字またはアンダースコアで始めます。それ以降は +// どれだけ長い文字、数値、アンダースコアを続けても構いません -function add ($x, $y = 1) { // $y is optional and defaults to 1 +function add ($x, $y = 1) { // $yはオプショナルな値であり、デフォルトで 1 です $result = $x + $y; return $result; } @@ -403,10 +403,10 @@ function add ($x, $y = 1) { // $y is optional and defaults to 1 echo add(4); // => 5 echo add(4, 2); // => 6 -// $result is not accessible outside the function -// print $result; // Gives a warning. +// $result には、関数の外からアクセス出来ません +// print $result; // エラーになります -// Since PHP 5.3 you can declare anonymous functions; +// PHP 5.3 から、無名関数が使えます $inc = function ($x) { return $x + 1; }; @@ -417,9 +417,9 @@ function foo ($x, $y, $z) { echo "$x - $y - $z"; } -// Functions can return functions +// 関数は、関数を返すことができます function bar ($x, $y) { - // Use 'use' to bring in outside variables + // 関数外の変数を利用したいときは、'use'を使います return function ($z) use ($x, $y) { foo($x, $y, $z); }; @@ -428,14 +428,15 @@ function bar ($x, $y) { $bar = bar('A', 'B'); $bar('C'); // Prints "A - B - C" -// You can call named functions using strings +// 文字列を使って、定義済みの関数を呼び出すことができます $function_name = 'add'; echo $function_name(1, 2); // => 3 -// Useful for programatically determining which function to run. -// Or, use call_user_func(callable $callback [, $parameter [, ... ]]); +// プログラミング中に、動的に動かす関数を決める場合に便利です。 +// もしくは、call_user_func(callable $callback [, $parameter [, ... ]]) を使っても同じことができます -// You can get the all the parameters passed to a function + +// 特に指定しなくても、渡された引数を受け取ることもできます function parameters() { $numargs = func_num_args(); if ($numargs > 0) { @@ -450,38 +451,39 @@ function parameters() { parameters('Hello', 'World'); // Hello | 0 - Hello | 1 - World | /******************************** - * Includes + * ファイルの読み込み */