swamp Posted July 22, 2009 Share Posted July 22, 2009 Hi I'm having a bit of trouble with this: In my loop I need to add the $i to the session name (eg) $i = 0; while ($i < 7) { doFunction($_SESSION["item".$i]) } Link to comment https://forums.phpfreaks.com/topic/166992-solved-increments/ Share on other sites More sharing options...
Maq Posted July 22, 2009 Share Posted July 22, 2009 A couple of issues: - You need session_start(); at the top of your script. - Your loop will result in an infinite loop. - What is the outcome you're getting and what outcome do you want? Link to comment https://forums.phpfreaks.com/topic/166992-solved-increments/#findComment-880470 Share on other sites More sharing options...
jcombs_31 Posted July 22, 2009 Share Posted July 22, 2009 You are never incrementing $i in your loop. $i++ Link to comment https://forums.phpfreaks.com/topic/166992-solved-increments/#findComment-880471 Share on other sites More sharing options...
swamp Posted July 22, 2009 Author Share Posted July 22, 2009 Yeah there is more to my script, my only concern is how to get $i into $_SESSION['item'$i] Link to comment https://forums.phpfreaks.com/topic/166992-solved-increments/#findComment-880474 Share on other sites More sharing options...
Maq Posted July 22, 2009 Share Posted July 22, 2009 Yeah there is more to my script, my only concern is how to get $i into $_SESSION['item'$i] The way you have it should work, after you increment your variable of course. It's also conventional to use single quotes for associative arrays rather than double. Link to comment https://forums.phpfreaks.com/topic/166992-solved-increments/#findComment-880475 Share on other sites More sharing options...
swamp Posted July 22, 2009 Author Share Posted July 22, 2009 Ah - was incrementing just started $i as 0 instead of 1... Cheers Link to comment https://forums.phpfreaks.com/topic/166992-solved-increments/#findComment-880476 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.