Array counfusion

问题描述 投票:0回答:1

我将下面的数组作为字符串。11 => A =>尝试,12 => B =>跳过,13 => A =>尝试,14 => A =>跳过,15 => B =>跳过,16 => A =>跳过但是我希望第一个键(12)跳过,如果用户执行某项操作,其值将改变,那么它应该返回下一个再次跳过的键(14)。我已经尝试过;

        //Converting to array
        for($i=0;$i<count($aa);$i++) {
            $x=explode('=>',$aa[$i]);
            $total_answer[$x[0]] = array($x[1],$x[2]);
          }
          // Matchhing option and question
          foreach($total_answer as $key=>$value)
          {
                  if($name=='Skip' || $name=="None")
                 {
                    $total_answer[$key][1]=$name;                 
              }
          }
php arrays laravel
1个回答
0
投票

我看到您有$name变量,但是没有一个数组指向name var,

$str="11=>A=>Attempt, 12=>B=>Skip, 13=>A=>Attempt, 14=>A=>Skip, 15=>B=>Skip, 16=>A=>Skip";

//first we need to separate from ,
$arr=explode(',',$str);

//initiate new array
$total_answer=[];

for($i=0;$i<count($arr);$i++)
{
    //dont forget to trim out space
    $x=explode('=>',trim($arr[$i]));
    $total_answer[$x[0]]= array($x[1],$x[2]);
}


foreach($total_answer as $key=>$value)
{
    //from where this $name variable come from?
    if($name=='Skip' || $name=="None")
    {
        $total_answer[$key][1]=$name;                 
    }
}

而且我对您的陈述感到困惑

但是我要使用第一个键(12),如果用户执行操作,该键将被跳过其值将更改,然后应返回下一个键(14),即再次跳过。我已经尝试过;

请输入您的输出目标。

© www.soinside.com 2019 - 2024. All rights reserved.