If you need to iterate in an array, you can simply use the for loops... and to see the amount of elements you have in an array, you can use the count() function. Here is an example: //we add data inside our array & create our array keys: $arr_data = array('index_01' => 'ananas', 'index_02' => 'bananas'); $arr_keys = array_keys($arr_data); //we then loop in ou array: for($i = 0; $i < count($arr_data); $i++) { echo $arr_data[$arr_key[$i]].'<br />'; } PHP:
Bah, make sure you always set the count variable before you put it in the loop, or it will be repeated each time. Real waste of memory. Dan
The count function just returns the next index of the array... it doesnt really calculate anything, just returns an integer. That beeing said, if you add the count values inside a variable, you will copy an integer inside another variable. In other words, if you want to use less memory, use count directly. Steve
This is not true, please check php.net/count. It's more efficient to save the count() value in a new variable because the count() function must go through all the array elements to return the last index.