One way to do this:
$params = [
'topresult' => $topresult,
'result' => $result,
];
if (!\Yii::$app->user->isGuest) {
$params['userresult'] = $userresult
}
return $this->render('index', $params);
Mixing echowith an array is obviously wrong. You should learn more about arrays in simple PHP.
array(), [], Yii2 PHP >= 5.4.
, null :
return $this->render('index', [
'userresult' => $userresult ?: null,
'topresult' => $topresult,
'result' => $result
]);
, null , if ($userresult) { ... }. , , isset. , .