Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAhmed AlKharraz
Front End Web Development Techdegree Graduate 25,735 PointsExplaining "for loop" for the challenge in "Browser Persistent Data with PHP"
Hello :)
Can someone explain this for loop in detail, please. I got the point of " if (!isset($_SESSION['word'][$i])) " but " if ($i == 1) " this one no.
for ($i = 1; $i <= 5; $i++) { if (!isset($_SESSION['word'][$i])) { if ($i == 1) { header('location:play.php'); exit; } else { header('location:play.php?p='.$i); exit; } } }
1 Answer
Steven Parker
231,269 PointsThe loop runs 5 times, and what "($i==1)
" does is to test "is this the first one?". If so, it uses the URL alone, but if it's any of the others it adds a query string parameter of "p=<the_number>
" onto the end.
You didn't provide a link to the course page, but I'd guess the "p" value is a page number.