I
I
Ilya2019-05-23 19:35:18
PHP
Ilya, 2019-05-23 19:35:18

How to check huge array and output data?

I have an array

$a = $d['as'][0]['as'][0]...['as'][0]['as'][0]['type']

['as'][0] - can be a HUGE number of times and always in different ways.
you need to somehow find the end, where type = object
and output ...['as'][0]['as'][0]['kod']

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Loginov, 2019-05-23
Dobryak @rusVolk

Use recursion:

function getKod($data){
    if( $data['type'] === 'object' ){
        return $data['kod'];
    }

    return getKod($data['as'][0]);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question