用定点识别前后(循环)

时间:2016-05-02 10:41:29

标签: php

尝试创建一个可重用的函数来重新创建这样的数组:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/coordinate"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.chivazo.chivazoandroid.activities.SingleProductActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginBottom="30dp"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/a"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_single_product" />


    <LinearLayout
        android:id="@+id/groupbutton"
        android:weightSum="2"
        android:orientation="horizontal"
        android:layout_gravity="bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <android.support.v7.widget.AppCompatButton
            android:layout_weight="1"
            android:id="@+id/share"
            android:text="share"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <android.support.v7.widget.AppCompatButton
            android:layout_weight="1"
            android:id="@+id/go_wishlist"
            android:text="go to Wishlist"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>


</android.support.design.widget.CoordinatorLayout>

我目前只是确定所有 ABOVE 活动步骤和 BELOW 活动步骤,并为他们提供正确的步骤ID

$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") ); 以上的所有内容都需要active-step分配给done-step值,其下方的数组应为step

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

沙箱链接试用: http://sandbox.onlinephpfunctions.com/code/c4b85c3d038560d8d3b4b5ad372f67a22df785c1

目前为止的功能如下:

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 ) )

1 个答案:

答案 0 :(得分:1)

只需查看您的函数,您就会有一个标识active状态的语句。

如果您专注于else语句,则可以执行以下操作

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

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