0

私の目標は、すべての配列値を別の配列に保持することですが、それを行う方法がわかりません。これが私の単純な配列です:

$grand_total = $total + $cost;
$cost_ratio = ($cost/$grand_total) * 100;
$paid_ratio = ($total/$grand_total) * 100;

$info[] = array(
             'id' => $data['id'],
             'ratio' => $cost_ratio,
             'status' => $status 
          );

これが私のサンプル配列出力です

Array
(
[0] => Array
    (
        [id] => 53
        [ratio] => 100
        [status] => C
    )

[1] => Array
    (
        [id] => 57
        [ratio] => 100
        [status] => I
    )

[2] => Array
    (
        [id] => 60
        [ratio] => 1.3157894736842
        [status] => I
    )

配列を作成したら、次に行うことは、比率を取得してこれをフィルタリングすることです。上記で見たように、変数があります$cost_ratio。この変数は、配列をフィルター処理する変数です。

これが私のコードの続きです:

 //declare a variable
 $var1 = 0;
 $var2 = 0;
 $var3 = 0;
 $var4 = 0;
 $var5 = 0;
 $var6 = 0;
 $var7 = 0;
 $var8 = 0;
 $var9 = 0;
 $var10 = 0;

その後

  for($x = 0; $x < sizeof($info); $x++){

            $status_info = $info[$x]['status'];
            $temp = $info[$x]['ratio'];

            /*this will set my filter*/

            /*if temp <= 9, i need to put all of my array that has a ratio <= 9*/

            if($temp <= 9){
                $var1++;
            }else if($temp <= 19){
                $var2++;
            }else if($temp <= 29){
                $var3++;
            }else if($temp <= 39){
                $var4++;
            }else if($temp <= 49){
                $var5++;
            }else if($temp <= 59){
                $var6++;
            }else if($temp <= 69){
                $var7++;
            }else if($temp <= 79){
                $var8++;
            }else if($temp <= 89){
                $var9++;
            }else{
                $var10++;
            }

      }

そして最後に私の記録を表示するためのテーブル

  echo "<table border='1'>";

        echo "<tr>";
            echo "<td>PERCENTAGE RANGE</td>";
            echo "<td>VOLUME</td>";
            echo "<td>RATIO</td>";
            echo "<td>BACKORDERED</td>";
            echo "<td>CANCELED</td>";
            echo "<td>COD APPROVED</td>";
            echo "<td>COD PENDING</td>";
            echo "<td>COD SHIPPED</td>";
            echo "<td>COMPLETED</td>";
            echo "<td>DECLINED</td>";
            echo "<td>FAILED</td>";
            echo "<td>FRAUD CHECKING</td>";
            echo "<td>PAID & WAITING SHIPPING</td>";
            echo "<td>PENDING</td>";
            echo "<td>SHIPPED</td>";
            echo "<td>TEST</td>";
            echo "<td>WAITING FOR APPROVAL</td>";
            echo "<td>WAITING PAYMENT</td>";
        echo "</tr>";

        echo "<tr>";
            echo "<td>10% - 90%</td>";
            echo "<td>".$var1."</td>"; <!-- IF ratio has a value between 1 - 9 go here -->
            echo "<td></td>";
            echo "<td>".$x1."</td>";
            echo "<td>".$x2."</td>";
            echo "<td>".$x3."</td>";
            echo "<td>".$x4."</td>";
            echo "<td>".$x5."</td>";
            echo "<td>".$x6."</td>";
            echo "<td>".$x7."</td>";
            echo "<td>".$x8."</td>";
            echo "<td>".$x9."</td>";
            echo "<td>".$x10."</td>";
            echo "<td>".$x11."</td>";
            echo "<td>".$x12."</td>";
            echo "<td>".$x13."</td>";
            echo "<td>".$x14."</td>";
            echo "<td>".$x15."</td>";          
        echo "</tr>";

        echo "<tr>";
            echo "<td>20% - 80%</td>"; <!-- IF ratio has a value between 10 - 19 go here -->
            echo "<td>".$var2."</td>";
            echo "<td></td>";
            echo "<td>".$x1."</td>";
            echo "<td>".$x2."</td>";
            echo "<td>".$x3."</td>";
            echo "<td>".$x4."</td>";
            echo "<td>".$x5."</td>";
            echo "<td>".$x6."</td>";
            echo "<td>".$x7."</td>";
            echo "<td>".$x8."</td>";
            echo "<td>".$x9."</td>";
            echo "<td>".$x10."</td>";
            echo "<td>".$x11."</td>";
            echo "<td>".$x12."</td>";
            echo "<td>".$x13."</td>";
            echo "<td>".$x14."</td>";
            echo "<td>".$x15."</td>";          
        echo "</tr>";
 .
 .

これが私がやりたいことです:

[ratio between 1 - 9 value] = array(
     [0] = array(
              'id' => 1,
              'status' => 'C'
           ),
     [1] = array(
              'id' => 3,
              'status' => 'D'
           ),
     [2] = array(
              'id' => 6,
              'status' => 'J'
           ),

),

[ratio between 10 - 19 value] = array(
     [0] = array(
              'id' => 1,
              'status' => 'C'
           ),
     [1] = array(
              'id' => 3,
              'status' => 'D'
           ),
     [2] = array(
              'id' => 6,
              'status' => 'J'
           ),

),
.
.
.

それが私がやりたいことですが、私はそれで苦労しています。

4

1 に答える 1