Php 用定点(回路)标识前后

Php 用定点(回路)标识前后,php,Php,尝试创建可重用函数以重新创建如下数组: $page_step_steps = array( array("id" => "1", "step" => "done-step"), 'main-active-step next-step-five', array("id" => "2", "step" => "done-step"), "main-active-step next-step-five", array("id" => "3", "ste

尝试创建可重用函数以重新创建如下数组:

$page_step_steps = array(
  array("id" => "1", "step" => "done-step"),
  'main-active-step next-step-five',
  array("id" => "2", "step" => "done-step"),
  "main-active-step next-step-five",
  array("id" => "3", "step" => "active-step"),
  "main-next-step next-step-five",
  array("id" => "4", "step" => "next-step"),
  "main-next-step next-step-five",
  array("id" => "5", "step" => "next-step")
);
我目前一直在识别活动步骤上方的和活动步骤下方的,并给他们正确的步骤ID

活动步骤
上方的所有内容都需要将
完成步骤
分配给
步骤
值,其下方的数组应具有
主活动步骤

但是,它下面的所有内容都应该有
next step
main next step

试用沙盒链接:

以下是目前为止的功能:

function formatting_steps($step, $steps){
  $page_step_steps = array();
  $steps_t = array(1 => "one", 2 => "two", 3 => "three", 4 => "four", 5 => "five", 6 => "six");
  $steps_f = $steps_t[$steps];
  $final_steps = $steps * 2;

  for($i = 1; $i < $final_steps; $i++){

    $r_step = round($i / 2, 0, PHP_ROUND_HALF_UP);

    if($i % 2){
      if($i == 1){
        $page_step_steps[$i]['id'] = $i;

        if($i == $step){
          $page_step_steps[$i]['step'] = "active-step";
        }
        else {
          $page_step_steps[$i]['step'] = $i;
        }
      }
      else {
        $page_step_steps[$i]['id'] = $r_step;

        if($r_step == $step){
          $page_step_steps[$i]['step'] = "active-step";
        }
        else {
          $page_step_steps[$i]['step'] = $i;
        }
      }
    }
    else {
      $page_step_steps[] = 'next-step-' . $steps_f;     
    }

  }

  $page_step_steps = $page_step_steps;

  return $page_step_steps;  
}
Array
(
    [1] => Array
        (
            [id] => 1
            [step] => 1
        )

    [2] => next-step-four
    [3] => Array
        (
            [id] => 2
            [step] => 3
        )

    [4] => next-step-four
    [5] => Array
        (
            [id] => 3
            [step] => active-step
        )

    [6] => next-step-four
    [7] => Array
        (
            [id] => 4
            [step] => 7
        )

)


编辑:在函数中传递以下内容:
格式化\u步骤(3,4)

仅查看函数,就有一条语句标识
活动状态

如果关注
else
语句,可以执行以下操作

if($step > $i){
    $page_step_steps[$i]['step'] = "done-step";             
}
else{               
    $page_step_steps[$i]['step'] = "next-step";
}


格式化\u步骤
功能的参数是什么?请详细说明。好的,明白了…………你能解释一下
3,4
做什么吗???你想要类似的东西吗
if($step > $r_step){
    $page_step_steps[$i]['step'] = "done-step";             
}
else{
    $page_step_steps[$i]['step'] = "next-step";
}