O
O
okovalev2019-02-18 19:05:27
PHP
okovalev, 2019-02-18 19:05:27

How to search in multidimensional array?

How to output "amount": 8.74 where value key is "alias": "qw_wallet_rub"?

{
    "accounts": [
        {
            "alias": "mc_beeline_rub",
            "fsAlias": "qb_mc_beeline",
            "bankAlias": "QIWI",
            "title": "MC",
            "type": {
                "id": "MC",
                "title": "Счет мобильного кошелька"
            },
            "hasBalance": false,
            "balance": null,
            "currency": 643
        },
        {
            "alias": "qw_wallet_rub",
            "fsAlias": "qb_wallet",
            "bankAlias": "QIWI",
            "title": "WALLET",
            "type": {
                "id": "WALLET",
                "title": "QIWI Wallet"
            },
            "hasBalance": true,
            "balance": {
                "amount": 8.74,
                "currency": 643
            },
            "currency": 643
        }
    ]
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Inishev, 2016-08-29
@leroyleroy

Maybe it's better to redo the routing system and issue the first match? Then it will be enough just to prescribe /admin before the regexp. Or even use a ready-made library for routing, since there are a lot of them.

T
trevoga_su, 2016-08-29
@trevoga_su

Or create a admin rule like '/admin/?'
or reconsider the "architecture" of virtual addresses and exclude global addresses like /anything
and do something like this:
/users/anything
/products/anything
/articles/anything

F
Freud's cat, 2019-02-18
@okovalev

Two nested within each other foreach. The first one searches "alias": "qw_wallet_rub"and passes execution to the nested foraech, which will already be searched in "balance", for this you will need to make a condition so that it does not iterate over the entire json.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question