php - Find value of specific key in multidimensional array -


from json feed receive multidimensional array below. array need values specific keys, value @ [payment_url]. i'm aware can value with

 $arr['transactions'][0]['payment_url']; 

but since documentation bit 'concise' i'm not sure if there response level.

henche, function feed key name , returns value unregarded on level key is. like

getvalue($arr, 'payment_url'); 

how do this?

array ( [amount] => 2525 [client] => array     (         [user_agent] => gingerphplib     )  [created] => 2016-01-15t21:35:17.032535+00:00 [currency] => eur [description] => description [flags] => array     (         [0] => is-test     )  [id] => xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx [merchant_order_id] => 205 [modified] => 2016-01-15t21:35:17.734427+00:00 [project_id] => xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx [return_url] => http://path/to/return/url/test [status] => new [transactions] => array     (         [0] => array             (                 [amount] => 2525                 [balance] => test                 [created] => 2016-01-15t21:35:17.231677+00:00                 [currency] => eur                 [description] => dit een omschrijving met een enter                 [id] => xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx                 [modified] => 2016-01-15t21:35:17.612664+00:00                 [payment_method] => ideal                 [payment_method_details] => array                     (                         [issuer_id] => ingbnl2a                     )                  [payment_url] => https://link/to/payment/                 [status] => new             )      )  ) 

from purely technical perspective could like

<?php $response = json_decode(data(), true); $flat = flatten($response);  echo $flat['payment_url'], ' | ', $flat['issuer_id'];  function flatten(array $arr) {     $rii = new recursiveiteratoriterator(new recursivearrayiterator($arr), recursiveiteratoriterator::leaves_only );     foreach( $rii $k=>$v) {         $rv[$k] = $v;     }     return $rv; }   function data() {     return <<< eoj [   {     "id": "1dc05e5f-c455-4f06-bc9f-37a2db3a75e1",     "created": "2014-07-14t10:13:50.726519+00:00",     "modified": "2014-07-14t10:13:51.593830+00:00",     "merchant_order_id": "example001",     "status": "new",     "type": "payment",     "amount": 995,     "currency": "eur",     "description": "example order #1",     "return_url": "http://www.example.com/",     "transactions": [       {         "id": "90b70bba-e298-4687-a2f2-095f7ebc9392",         "created": "2014-07-14t10:13:51.082946+00:00",         "modified": "2014-07-14t10:13:51.210838+00:00",         "status": "new",         "currency": "eur",         "amount": 995,         "description": "example order #1",         "expiration_period": "p30d",         "balance": "internal",         "payment_method": "ideal",         "payment_method_details": {           "issuer_id": "ingbnl2a"         },         "payment_url": "https://api.gingerpayments.com/redirect/90b70bba-e298-4687-a2f2-095f7ebc9392/to/payment/"       }     ]   } ] eoj; } 

see http://docs.php.net/recursiveiteratoriterator , http://docs.php.net/recursivearrayiterator

but i'm rather suspicious reason using given in question. suggest investigate "problem" further , not use this.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -