0

我使用了一个小脚本来导入 mt940 文件(荷兰银行交易文件)。

这是我返回的数组,但我需要一点帮助才能从数组中获取正确的值。

Array (
    [0] => Statement_banking Object (
        [_bank:Statement_banking:private] => ING
        [_account:Statement_banking:private] => 111111111
        [_transactions:Statement_banking:private] => Array (
            [0] => Transaction_banking Object (
                [account:Transaction_banking:private] => 111111111
                [accountName:Transaction_banking:private] => V. DE JONG KERKSTRAAT 1154 1234 BW
                [price:Transaction_banking:private] => 0.56
                [debitcredit:Transaction_banking:private] => C
                [description:Transaction_banking:private] => 0111111111 V. DE JONG KERKSTRAAT 1154 1234 BW ENSCHEDE BET.KENM. 1004510036716378 3305330802 AFLOSSINGSTERMIJN 188616 / 1E TERMIJN
                [valueTimestamp:Transaction_banking:private] => 1279749600
                [entryTimestamp:Transaction_banking:private] => 1279749600
                [transactionCode:Transaction_banking:private] => 078
            )
            [1] => Transaction_banking Object (
                [account:Transaction_banking:private] => 111111111 
                [accountName:Transaction_banking:private] => CUSTOMER NL SPOEDBETALING 
                [price:Transaction_banking:private] => 10.45 
                [debitcredit:Transaction_banking:private] => C 
                [description:Transaction_banking:private] => 0111111111 CUSTOMER NL SPOEDBETALING GE2009120212345 RE091202­3737 /RFB/NL­FMI­021209 NL­FMI­021209 VOORSCHOT COMMISSIE
                [valueTimestamp:Transaction_banking:private] => 1279749600 
                [entryTimestamp:Transaction_banking:private] => 1279749600 
                [transactionCode:Transaction_banking:private] => 077
            )
            [2] => Transaction_banking Object (
                [account:Transaction_banking:private] => 
                [accountName:Transaction_banking:private] => 
                [price:Transaction_banking:private] => 10000.99 
                [debitcredit:Transaction_banking:private] => D 
                [description:Transaction_banking:private] => VERZAMELBETALING BATCH­ID: 012345 TOTAAL 198 POSTEN 
                [valueTimestamp:Transaction_banking:private] => 1279749600 
                [entryTimestamp:Transaction_banking:private] => 1279749600 
                [transactionCode:Transaction_banking:private] => 029 ) )
                [_startPrice:Statement_banking:private] => 44 
                [_endPrice:Statement_banking:private] => 9945 
                [_timestamp:Statement_banking:private] => 1279749600 
                [_number:Statement_banking:private] => 100
            )
        )

例如,这个键给了我名字和地址:

[accountName:Transaction_banking:private] => V. DE JONG KERKSTRAAT 1154 1234 BW

这把钥匙给了我交易价格:

[price:Transaction_banking:private] => 0.56

有什么建议么?

4

2 回答 2

1

逻辑上您需要使用嵌套的 foreach 或 for 循环,不确定语法但下面的 PHP 代码可能会对您有所帮助,然后您可以转换为所需的语言

  $outputArr = Is your array.
  foreach ( $outputArr as $firstchild){
   forach ( $firstchild as $key => $secondchildvalue){
     // $key is basically your key value [price:Transaction_banking:private]
     // $secondchildvalue is your info value 0.56
   }
  }
于 2013-02-20T08:58:53.313 回答
1

通常,您将访问地址和交易价格:

foreach( $yourArray[0]->_transactions as $transaction ) {
    $foo = $transaction->accountName;
    $bar = $transaction->price;
}

但是在这种特殊情况下,您的某些字段是私有的,这意味着您无法直接访问它们的值。您可以尝试定义自己的Statement_bankingTransaction_banking类,并为这些字段定义访问器方法,例如:

public class Statement_banking {
    public function getTransactions() {
        return $this->_transactions;
    }
}

public class Transaction_banking {
    public function getAccountName() {
        return $this->accountName;
    }

    public function getPrice() {
        return $this->price;
    }
}

然后你的循环代码变成这样:

foreach( $yourArray[0]->getTransactions() as $transaction ) {
    $foo = $transaction->getAccountName();
    $bar = $transaction->getPrice();
}

如果您还想遍历外部数组,可以将其扩展为:

foreach( $yourArray as $statement ) {
    foreach( $statement->getTransactions() as $transaction ) {
        $foo = $transaction->getAccountName();
        $bar = $transaction->getPrice();
    }
}
于 2013-02-20T09:03:57.903 回答