Hello all,
I’m trying to add a counter when I use a foreach loop on my multidimensional array. For example, key 6 has two arrays while key 22 has one array.
At the moment, the foreach loop prints out:
27
12
4
What I need is:
1 27
2 12
1 4
Any ideas? I’d be grateful for any assistance with this. Thanks a lot!
Here’s the array:
array (size=2)
6 =>
array (size=2)
27 =>
array (size=1)
9 => string 'JavaScript' (length=10)
12 =>
array (size=1)
14 => string 'jQuery' (length=6)
22 =>
array (size=1)
4 => string 'PHP' (length=3)
My current foreach loop:
foreach($ar as $k => $v){
foreach($v as $k2 => $v2){
echo "<p>$k2</p>";
}
}