0

I've used a little script for importing mt940 files (file of dutch bank transactions).

This is the array I get back but I need a little bit help to get the right values out of the array.

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

This key for example gives me the name and the address:

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

This key gives me the transaction price:

[price:Transaction_banking:private] => 0.56

Any suggestions?

1
  • Those are private properties of Transaction_banking and Statement_banking classes. What do the classes look like? There probably is a method for retrieving the data. Commented Feb 20, 2013 at 8:58

2 Answers 2

1

Normally you would access the address and transaction price as:

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

But in this particular case, some of your fields are private, meaning that you can't access their value directly. You could try defining your own Statement_banking and Transaction_banking classes and define accessor methods for those fields, such as:

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;
    }
}

Then your loop code becomes this:

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

If you want to iterate over the outer array as well, you can expand it to:

foreach( $yourArray as $statement ) {
    foreach( $statement->getTransactions() as $transaction ) {
        $foo = $transaction->getAccountName();
        $bar = $transaction->getPrice();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

Logically You need to use nested foreach or for loop, Not sure about syntax but below PHP code may help you and then you may convert in required language

  $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
   }
  }

1 Comment

This won't work. They are private properties, price:Transaction_banking:private is not the key. The whole point of them being private is so you can't directly access them outside the class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.