0

如何将当前数组值与之前的数组值进行比较。例如,如果我有以下数组并想将 [BM1367 PD C 70][ST00576]['transferfrom'] 与之前的数组 [BM1367 PD B 85] 进行比较[ST00576]['转自']?

    [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

                )

        )

)
4

2 回答 2

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
于 2012-07-02T03:19:38.647 回答
0

您询问:

如何将当前数组值与之前的数组值进行比较

我想你可能想看看以下 PHP 函数

  1. 当前() - http://www.php.net/manual/en/function.current.php
  2. prev() - http://www.php.net/manual/en/function.prev.php
  3. next() - 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';
?>

我能够在计算公式上使用它们,工作很棒!在比较您的上一个或下一个数组的电流时,它也很有用。

于 2012-07-02T03:29:23.890 回答