0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHP基礎メモその4

Posted at

$_GET

$_GETはクエリ情報を受け取るのに用いる。$_GETにはクエリ情報が連想配列として入っている。
よって、$_GET['キー名']のように値をとりだすことができる。

index.php
CURRY ```

href属性のnameがキー名でCURRYが値となる

show.php

echo $_GET['name'];
// キー名を指定して値を取り出す


結果
CURRY

>```php:$_GETの中身(連想配列)
array(
  'name'=>'CURRY'
  // キー名=>値
)

return

returnには戻り値を指定するだけではなく、returnが呼ばれた部分で関数やメソッドの処理を終了させるという性質がある。

function getLargerNum($num1, $num2) {
if($num > $num2) {
echo '$num1は$num2より大きい';
return $num;
}
// 上記のif文内のreturnが呼ばれると、この処理は実行されない
echo '$num2は$num1より大きいか、$num1と同じ';
return $num2;
}

```php
$result = getLargerNum(5, 1);
>
echo $result;

結果
$num1は$num2より大きい
5

class Menu {
public static function findByName($menus, $name) {
foreach($menus as $menu) {
// インスタンスのnameプロパティの値と$nameの値が一致したら、そのインスタンスを返す
if($menu->getName() == $name) {
return $menu;
}
}
}
}


0
0
0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?