您好我只是想知道是否有更好的办法做这样的事情:一个更好的方法,如果一个变量isset PHP
$openid = $_SESSION['openiduserdata'];
if (isset($openid['namePerson/friendly']))
{$username = $openid['namePerson/friendly'];}
if (isset($openid['namePerson/first']))
{$firstname = $openid['namePerson/first'];}
if (isset($openid['namePerson/last']))
{$lastname = $openid['namePerson/last'];}
if (isset($openid['birthDate']))
{$birth = $openid['birthDate'];}
if (isset($openid['contact/postalCode/home']))
{$postcode = $openid['contact/postalCode/home'];}
if (isset($openid['contact/country/home']))
{$country = $openid['contact/country/home'];}
if (isset($openid['contact/email']))
{$email = $openid['contact/email'];}
现在还不清楚要如何处理在您的示例代码默认(看起来像您以后需要再次探讨每个变量的存在)。但是你可能想使用一个数组映射而不是单个的'if'语句。 – mario
我有一个问题:为什么你需要把三次相同的值放在内存中? $ _SESSION ['openiduserdata'],$ openid和$ username等等。 – corretge