如何绕过Laravel中未定义的偏移量1

时间:2018-06-27 19:49:05

标签: laravel

请帮助绕过该数组。...

此函数假定返回2个用户,但是最初当他们首次注册时只有1个用户可用,这将对“ $ right”有效,但是当到达“ $ left”时,它将返回“ undefined offset 1”

$direct = $this->loaduser($userid);

$right = $this->loaduserdirect($direct[0]->user_id);

$left = $this->loaduserdirect(isset($direct[1]->user_id));

if(($user->boosted == 1) && ($direct[0]->boosted == 1) || ($direct[1]- 
>boosted == 1)){
if (isset($bonus['point']))
    $stageBonus->point = $stageBonus->point+$bonus['point'];

if (isset($bonus['totalultimarefbonus']))
    $stageBonus->cash = $stageBonus- 
>cash+$bonus['totalultimarefbonus'];

} else if(($user->boosted == 1) && ($direct[0]->boosted == 1) && 
($direct[1]->boosted == 0)){
if (isset($bonus['point']))
    $stageBonus->point = $stageBonus->point+$bonus['point'];

if (isset($bonus['ultimarefbonus']))
    $stageBonus->cash = $stageBonus->cash+$bonus['ultimarefbonus'];

} else if(($user->boosted == 1) && ($direct[0]->boosted == 0) && 
($direct[1]->boosted == 1)){
if (isset($bonus['point']))
    $stageBonus->point = $stageBonus->point+$bonus['point'];

if (isset($bonus['ultimarefbonus']))
    $stageBonus->cash = $stageBonus->cash+$bonus['ultimarefbonus'];

1 个答案:

答案 0 :(得分:0)

我要这样做:

$direct = $this->loaduser($userid);

$right = $this->loaduserdirect($direct[0]->user_id);

if(count($direct) > 1) {
  $left = $this->loaduserdirect($direct[1]->user_id);
}