我有这段代码
class rfs_payeer
{
private $url = 'https://payeer.com/ajax/api/api.php';
private $agent = 'Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0';
private $auth = array();
private $output;
private $errors;
/*======================================================================*\
Function: __construct
Descriiption: Выполняется при создании экземпляра класса
\*======================================================================*/
public function __construct($account, $apiId, $apiPass)
{
$arr = array(
'account' => $account,
'apiId' => $apiId,
'apiPass' => $apiPass,
);
$this->auth = $arr;
}
public function isAuth()
{
if (!empty($this->auth)){ return true;
}
else{
return $this->auth['account'];
}
}
}
如何从$arr['account']
获取isAuth()
?
答案 0 :(得分:0)
我认为你所寻找的更像是......
class rame
{
private $arr=Array();
public function func()
{
$this->arr =array(
"pir"=>"pirveli",
"me"=>"meore",
"mes"=>"mesame"
);
echo $this->arr['pir'];
}
}
$r = new rame();
$r->func();
答案 1 :(得分:0)
您正在正确访问它,但您的if
条件错误。您正在检查数组是否不为空,因此您不会进入else
部分。删除!
运算符:
if (empty($this->auth)) {
return true;
} else {
return $this->auth['account'];
}
查看它与eval.in
上的输出一起运行或者,使用三元运算符:
return empty($this->auth) ? true : $this->auth['account'];
注意:当阵列为空时,您确定要返回true
吗?返回空字符串false
或null
似乎更合理。
要实际查看结果,您必须:
$this->auth
(不要在评论的其他示例中与$auth
相似)isAuth