2012-07-02 100 views
0

如何比較當前數組值與以前的數組值?示例如果我有以下數組並且想比較[BM1367 PD C 70] [ST00576] ['transferfrom']與先前的數組是[BM1367 PD B 85] [ST00576] ['transferfrom']?將數組值與前一個數組值比較

[BM1367 PD B 85] => Array 
     (
      [ST00576] => stdClass Object 
       (
        [transferfrom] => 102 
        [transferto] => 66 
        [BR_ID] => 102 
        [refno] => 

       ) 

      [OT01606] => stdClass Object 
       (
        [transferfrom] => 102 
        [transferto] => 66 
        [BR_ID] => 66 
        [refno] => 102 - ST00576 

       ) 

     ) 

    [BM1367 PD C 70] => Array 
     (
      [ST00576] => stdClass Object 
       (
        [transferfrom] => 102 
        [transferto] => 66 
        [BR_ID] => 102 
        [refno] => 

       ) 

      [OT01606] => stdClass Object 
       (
        [transferfrom] => 102 
        [transferto] => 66 
        [BR_ID] => 66 
        [refno] => 102 - ST00576 

       ) 

     ) 

    [BM1367 PD C 85] => Array 
     (
      [ST00576] => stdClass Object 
       (
        [transferfrom] => 102 
        [transferto] => 66 
        [BR_ID] => 102 
        [refno] => 

       ) 

      [OT01606] => stdClass Object 
       (
        [transferfrom] => 102 
        [transferto] => 66 
        [BR_ID] => 66 
        [refno] => 102 - ST00576 

       ) 

     ) 

    [BM1367 PD D 85] => Array 
     (
      [ST00576] => stdClass Object 
       (
        [transferfrom] => 102 
        [transferto] => 66 
        [BR_ID] => 102 
        [refno] => 

       ) 

      [OT01606] => stdClass Object 
       (
        [transferfrom] => 102 
        [transferto] => 66 
        [BR_ID] => 66 
        [refno] => 102 - ST00576 

       ) 

     ) 

) 
+0

我已經試過: 的foreach($轉移爲$ docno => $ transfer_details){ //做的東西在這裏 } $ previous_br =電流(array_map( 'pick_transferfrom',$傳輸)); \t} – redcoder

回答

0

你問:

我怎麼與以前的數組值比較當前數組值

我想你可能想看看下面的PHP函數

  1. 電流() - http://www.php.net/manual/en/function.current.php
  2. prev() - http://www.php.net/manual/en/function.prev.php
  3. 下一個() - http://php.net/manual/en/function.next.php

例如:

<?php 
$transport = array('foot', 'bike', 'car', 'plane'); 
$mode = current($transport); // $mode = 'foot'; 
$mode = next($transport); // $mode = 'bike'; 
$mode = next($transport); // $mode = 'car'; 
$mode = prev($transport); // $mode = 'bike'; 
$mode = end($transport);  // $mode = 'plane'; 
?> 

我能夠使用那些在計算公式,工作的偉大!比較您的前一個或下一個陣列的電流時,它也很有用。

0

你的STD class objects在這種情況下,一個數組,你可以按如下比較元素: 假設另一個數組裏面,你所提供的陣列是

$tempArray = { 


     [BM1367 PD B 85] => Array 
      (
       [ST00576] => stdClass Object 
        (
         [transferfrom] => 102 
         [transferto] => 66 
         [BR_ID] => 102 
         [refno] => 

        ) 

       [OT01606] => stdClass Object 
        (
         [transferfrom] => 102 
         [transferto] => 66 
         [BR_ID] => 66 
         [refno] => 102 - ST00576 

        ) 

      ) 

     [BM1367 PD C 70] => Array 
      (
       [ST00576] => stdClass Object 
        (
         [transferfrom] => 102 
         [transferto] => 66 
         [BR_ID] => 102 
         [refno] => 

        ) 

       [OT01606] => stdClass Object 
        (
         [transferfrom] => 102 
         [transferto] => 66 
         [BR_ID] => 66 
         [refno] => 102 - ST00576 

        ) 

      ) 

     [BM1367 PD C 85] => Array 
      (
       [ST00576] => stdClass Object 
        (
         [transferfrom] => 102 
         [transferto] => 66 
         [BR_ID] => 102 
         [refno] => 

        ) 

       [OT01606] => stdClass Object 
        (
         [transferfrom] => 102 
         [transferto] => 66 
         [BR_ID] => 66 
         [refno] => 102 - ST00576 

        ) 

      ) 

     [BM1367 PD D 85] => Array 
      (
       [ST00576] => stdClass Object 
        (
         [transferfrom] => 102 
         [transferto] => 66 
         [BR_ID] => 102 
         [refno] => 

        ) 

       [OT01606] => stdClass Object 
        (
         [transferfrom] => 102 
         [transferto] => 66 
         [BR_ID] => 66 
         [refno] => 102 - ST00576 

        ) 

      ) 

    ) 

}; 

您現在可以訪問元素

$tempArray['BM1367 PD C 70']['ST0076']->transferfrom 

$tempArray['BM1367 PD B 85']['ST0076']->transferfrom 

並且爲了比較它們

(int)$tempArray['BM1367 PD C 70']['ST0076']->transferfrom == (int)$tempArray['BM1367 PD B 85']['ST0076']->transferfrom