W
W
WQP2015-10-25 18:42:35
PHP
WQP, 2015-10-25 18:42:35

How to find the element number in a loop?

There is a design:

foreach ($data as $key => $value) {
   foreach ($value['users']['items'] as $ky => $val) {
   ...
   }
}

How to find out what is the current common element? those. need $key + $ky

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
maximw, 2015-10-25
@WQP

Maybe so?

$i = 0;
foreach ($data as $key => $value) {
   foreach ($value['users']['items'] as $ky => $val) {
   ...
        $i++;
        echo $i;
   }
}

D
Dimonchik, 2015-10-25
@dimonchik2013

so it will be
or what is needed

V
Vyacheslav, 2015-10-26
@nskarl

so you also have a $key
just echo $key;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question