# How do I loop through an indexed array?

**URL:** <https://forum.kirupa.com/t/how-do-i-loop-through-an-indexed-array/275002>\
**Category:** programming\
**Created:** [November 7, 2008, 5:04pm UTC](https://forum.kirupa.com/t/how-do-i-loop-through-an-indexed-array/275002 "2008-11-07T17:04:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![charles\_i](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/charles_i/32/2986_2.png) [@charles\_i](https://forum.kirupa.com/u/charles_i)\
**Post date:** [November 7, 2008, 5:04pm UTC](https://forum.kirupa.com/t/how-do-i-loop-through-an-indexed-array/275002/1 "2008-11-07T17:04:23Z")

</div>

This should be pretty simple but all the searches I do turn up looping through an associative array. I’ve created an array in a Session contining links clicked so that when someone returns from a thank you page the links they clicked on can be disabled. When you go from the page with links to the thank you page I add it to the Session array:

//add $linkVisted array to the session  
$\_SESSION[‘linkVisted’] = $linkVisted;

//add the next number to the array  
array\_push($linkVisted,$link);

This works and returns the following output when I return to the links page:

Array ( [linkVisted] =\> Array ( [0] =\> 3 [1] =\> 3 [2] =\> 1 [3] =\> 1 [4] =\> 8 [5] =\> 9 ) )

Now, how do I loop through this array to compare each link’s number with these numbers? When I try this I get an array length of 1 - because there is only one array - so how do get the number of elements (9 here) and loop through them?

for ($i = 1; $i \< count($linkVisted); ++$i) {  
echo $linkVisted[$i];  
}

Thanks!  
P.S. The Kirupa form field doesn’t work in Firefox. Can’t see a cursor, can’t delete :([URL=“[http://www.kirupa.com/forum/newthread.php?do=postthread&f=11](http://www.kirupa.com/forum/newthread.php?do=postthread&f=11)”]
