What does the PHP syntax $var1->$var2 mean?

后端 未结 3 2037
半阙折子戏
半阙折子戏 2020-12-18 01:43

What is the explanation for the following syntax?

$var1->$var2 // Note the second $
3条回答
  •  北海茫月
    2020-12-18 02:25

    You are calling a property on $var1 that is named the same as the value of $var2.

    For example:

    $var2 = "name";
    
    // The following are equivalent
    $var1->name;
    $var1->$var2;
    

提交回复
热议问题