我是OOP的新手,我看到了这样的代码示例:
$mp->people->set(12345, array(
'$first_name' => "John",
'$last_name' => "Doe"
));
如何在此OOP代码中使用常规php变量...例如:
$userid = 12345;
$firstname = "john";
$lastname = "doe";
例如(这不起作用)
$mp->people->set($userid, array(
'$first_name' => "$firstname",
'$last_name' => "$lastname"
));
感谢您的帮助
答案 0 :(得分:0)
使用double quotes。我不确定我的问题是否正确。你必须使用它们,如果你想用变量值替换键:
$mp->people->set(12345, array(
"$first_name" => "John",
"$last_name" => "Doe"
));
或者如果您想要用它们替换值,只需指定变量的值:
$mp->people->set(12345, array(
'first_name' => $first_name,
'last_name' => $last_name
));