PHP 解析返回的对象

PHP Parse returned Object

当我试图在 https://github.com/fruitl00p/php-mt940 的帮助下从 ING 读取 mt940 文件时,我尝试了他的测试文件。它 returns 像这样。

array(1) { [0]=> object(Kingsquare\Banking\Statement)#4 (9) { 
["bank":"Kingsquare\Banking\Statement":private]=> string(3) "ING" 
["account":"Kingsquare\Banking\Statement":private]=> string(9) "111111111" 
["transactions":"Kingsquare\Banking\Statement":private]=> array(3) { 
    [0]=> object(Kingsquare\Banking\Transaction)#5 (9) { 
        ["account":"Kingsquare\Banking\Transaction":private]=> string(9) "111111111" 
        ["accountName":"Kingsquare\Banking\Transaction":private]=> string(34) "V. DE JONG KERKSTRAAT 1154 1234 BW" 
        ["price":"Kingsquare\Banking\Transaction":private]=> float(0.56) 
        ["debitcredit":"Kingsquare\Banking\Transaction":private]=> string(1) "C" 
        ["cancellation":"Kingsquare\Banking\Transaction":private]=> bool(false) 
        ["description":"Kingsquare\Banking\Transaction":private]=> string(128) "0111111111 V. DE JONG KERKSTRAAT 1154 1234 BWENSCHEDE BET.KENM. 1004510036716378 3305330802AFLOSSINGSTERMIJN 188616 / 1E TERMIJN" 
        ["valueTimestamp":"Kingsquare\Banking\Transaction":private]=> int(1279737000) 
        ["entryTimestamp":"Kingsquare\Banking\Transaction":private]=> int(1279737000) 
        ["transactionCode":"Kingsquare\Banking\Transaction":private]=> string(3) "078" } 
    [1]=> object(Kingsquare\Banking\Transaction)#6 (9) { 
        ["account":"Kingsquare\Banking\Transaction":private]=> string(9) "111111111" 
        ["accountName":"Kingsquare\Banking\Transaction":private]=> string(25) "CUSTOMER NL SPOEDBETALING" 
        ["price":"Kingsquare\Banking\Transaction":private]=> float(10.45) 
        ["debitcredit":"Kingsquare\Banking\Transaction":private]=> string(1) "C" [
        "cancellation":"Kingsquare\Banking\Transaction":private]=> bool(false) 
        ["description":"Kingsquare\Banking\Transaction":private]=> string(120) "0111111111 CUSTOMER NL SPOEDBETALINGGE2009120212345RE091202­3737 /RFB/NL­FMI­021209 NL­FMI­021209VOORSCHOTCOMMISSIE" ["valueTimestamp":"Kingsquare\Banking\Transaction":private]=> int(1279737000) 
        ["entryTimestamp":"Kingsquare\Banking\Transaction":private]=> int(1279737000) 
        ["transactionCode":"Kingsquare\Banking\Transaction":private]=> string(3) "077" } 
} 
["startPrice":"Kingsquare\Banking\Statement":private]=> float(44.89) 
["endPrice":"Kingsquare\Banking\Statement":private]=> float(-9945.09) 
["startTimestamp":"Kingsquare\Banking\Statement":private]=> int(1279737000) 
["endTimestamp":"Kingsquare\Banking\Statement":private]=> int(1279823400) 
["number":"Kingsquare\Banking\Statement":private]=> string(3) "100" 
["currency":"Kingsquare\Banking\Statement":private]=> string(3) "EUR" } } 

这里 returns 和 'Kingsquare\Banking\Statement'。我如何从条目结果中删除它,以及如何从返回的结果中获取 'bank'、'account'、开始价格、结束价格和货币。

这是我试过的 php 程序。

require 'vendor/autoload.php';

$parser = new \Kingsquare\Parser\Banking\Mt940();

$tmpFile = __DIR__ . '/test.mta';
$trans = $parser->parse(file_get_contents($tmpFile));

var_dump($trans);

您拥有这些名称空间是因为您正在转储变量,要获取您需要的值,只需使用语句 class:

提供的 getter 函数
$statement = $parser->parse(file_get_contents($tmpFile));

echo $statement[0]->getBank();
echo $statement[0]->getAccount();
echo $statement[0]->getStartPrice();
echo $statement[0]->getEndPrice();
echo $statement[0]->getCurrency();