Reputation: 176
I'm updating software that will import XML file of bank statement to invoicing software. One of the operations is through iteration looking for values in the structure of xml file (which the file itself is converted to associative array at this point).
What I would like to achieve is to set some sort of map in config file for the rest of the software to use, that would show where to look for specific data in that associative array, like date of the transaction, cash amount payed and other.
So first cfg map array:
"map"=>array(
"date"=>"ARRAY['exec-date']",
"amount"=>"ARRAY['amount']['value']"
);
And then use that map to get appropriate values based (from XML) using structure provided in those key values using Variable-variables:
$amount = ${$map['amount']};
Is that even possible? Or am I that tired and it's very easy and I'm just blocked?
Upvotes: 2
Views: 36
Reputation: 782130
You can use anonymous functions:
$map = array(
"date" => function($x) { return $x['exec-date']; },
"amount" => function($x) { return $x['amount']['value']; }
);
Then you would do:
$amount = $map['amount']($xml);
Upvotes: 2