get key position inside foreach loop in complex array

I am iterating through a complex array created from wierd xml.
I want to store the position of each key as part of the form that gets populated submits back into the array

The array looks like:

    [Data] => Array
            [Item] => Array
                    [0 attr] => Array
                            [id] => 1
                            [name] => Animation For Acorn Property Group
                            [body] => assets/text/news_acorn.txt
                            [date] => 17/12/08
                            [thumbnail] => assets/images/news_acorn_th.jpg

                    [0] =>
                    [1 attr] => Array
                            [id] => 2
                            [name] => Crosby Lend Lease Hub development
                            [body] => assets/text/news_hub.txt
                            [date] => 17/12/08
                            [thumbnail] => assets/images/hub3_th.jpg

and my code that pulls out the data:

      $mystr = '';
      foreach ($data["Data"]["Item"] as $key=>$value) {
            if(is_array($value)) {
                  $mykeys = array_keys($value);
                  foreach ($mykeys as $skey=>$svalue) {
                        $mystr .= getHtml($svalue, $value[$svalue], $pos);

i've tried $pos = key($data["Data"]["Item"]) after the first foreach

but I get only '0 attr' back for all values.

Any way to return the position of  [0 attr], [1 attr], etc?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

foreach ($data["Data"]["Item"] as $key=>$value) {

$key by itself is the key position in the loop.
foreach ($data["Data"]["Item"] as $key=>$value) {
  echo $key;

will output 1,2,3,4,5,6,7,8 etc.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
antonumiaAuthor Commented:
that nearly worked although it returned
1 attr, 1, 2 attr, 2

I think it's the array at fault.
and bit of fiddling and this worked great!


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.