return an index of an associative array
Posted: Mon Jan 16, 2012 10:24 am
Hello all,
I am trying to find a way to loop through an associative array in order to return the index of each item in the array, for instance if I have the data(as returned from var_dump):
[text]
array
1 => string 'FIRST ITEM' (length=16)
112 => string 'SECOND ITEM' (length=19)
[/text]
I want to loop through the array and output the index of each item
so if I loop through the array my output should display 1, 112
I tried key($array) but this returns null. I am assuming this is looking for a string value
Thanks
I am trying to find a way to loop through an associative array in order to return the index of each item in the array, for instance if I have the data(as returned from var_dump):
[text]
array
1 => string 'FIRST ITEM' (length=16)
112 => string 'SECOND ITEM' (length=19)
[/text]
I want to loop through the array and output the index of each item
so if I loop through the array my output should display 1, 112
I tried key($array) but this returns null. I am assuming this is looking for a string value
Thanks