LoginSignup
18
11

More than 3 years have passed since last update.

PHPの矢印の意味 アロー演算子「->」とダブルアロー演算子「=>」 

Posted at

アロー演算子「->」

アロー演算子はその左辺にはクラスのインスタンスを取り、右辺には左辺のクラスが持つプロパティ(変数)やメソッド(関数)を指定しプロパティへのアクセス・メソッドの呼び出しを実行します。

// 人間クラス
class Person {
    $name;

    function __construct($name) {
        $this->name = $name;
    }
    function introduceSelf() {
        echo "私の名前は". $this->name"です";
    }
}

$taro = new Person("太郎");
echo $taro->$name;
$taro->introduceSelf();

ダブルアロー演算子「=>」

連想配列キーとバリューを示すためのもの

return view('buy/index', ['cartitems' => $cartitems, 'subtotal'=> $subtotal]);

$array = array('apple'=>'りんご', 'peach'=>'もも', 'pear'=>'なし');
18
11
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
18
11