dennismonsewicz Posted March 30, 2009 Share Posted March 30, 2009 code: $status_array = array('Pending', 'Followup', 'Approved', 'Completed', 'Rejected', 'Correction'); for($i = 0; $i > sizeof($status_array); $i++) { foreach($status_array as $arr) { $option = '<option name=' . $arr . ' value=' . $arr . '>' . $arr . '</option>'; } } I have a select that I am trying to echo out the options for by looping through the array... but when I echo out $options I get nothing... any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/151843-solved-looping-help/ Share on other sites More sharing options...
Maq Posted March 30, 2009 Share Posted March 30, 2009 You need to use double quotes for $option: $option = "'$arr"; I think you're using too many loops as well... $status_array = array('Pending', 'Followup', 'Approved', 'Completed', 'Rejected', 'Correction'); foreach($status_array as $arr) $option .= "$arr"; Quote Link to comment https://forums.phpfreaks.com/topic/151843-solved-looping-help/#findComment-797348 Share on other sites More sharing options...
lonewolf217 Posted March 30, 2009 Share Posted March 30, 2009 you dont need the for loop, just use the foreach Quote Link to comment https://forums.phpfreaks.com/topic/151843-solved-looping-help/#findComment-797349 Share on other sites More sharing options...
sdi126 Posted March 30, 2009 Share Posted March 30, 2009 both posts make valid points...no need for two loops foreach ($arr as $value) { //your code here } also option is being overwritten each time in the loop...use += $option += '<option name="'.$arr.'" value="'.$arr.'">'.$arr.'</option>'; Quote Link to comment https://forums.phpfreaks.com/topic/151843-solved-looping-help/#findComment-797352 Share on other sites More sharing options...
Maq Posted March 30, 2009 Share Posted March 30, 2009 also option is being overwritten each time in the loop...use += That's for addition. We're concatenating strings here, so use ".=" like in my previous post. Quote Link to comment https://forums.phpfreaks.com/topic/151843-solved-looping-help/#findComment-797354 Share on other sites More sharing options...
sdi126 Posted March 30, 2009 Share Posted March 30, 2009 sorry...Maq your right...im @ work now...we are strictly ASP.NET (c#) which is the mode i am in now. Quote Link to comment https://forums.phpfreaks.com/topic/151843-solved-looping-help/#findComment-797357 Share on other sites More sharing options...
Maq Posted March 30, 2009 Share Posted March 30, 2009 we are strictly ASP.NET (c#) which is the mode i am in now. Boooo! Quote Link to comment https://forums.phpfreaks.com/topic/151843-solved-looping-help/#findComment-797359 Share on other sites More sharing options...
sdi126 Posted March 30, 2009 Share Posted March 30, 2009 yea...i hate it...but what can i do...im just one disgruntled employee Quote Link to comment https://forums.phpfreaks.com/topic/151843-solved-looping-help/#findComment-797360 Share on other sites More sharing options...
dennismonsewicz Posted March 31, 2009 Author Share Posted March 31, 2009 Just got back to this forum didn't know this post would bring forth such a discussion HAHA. yeah I work in an evironment of open source guys and .NET guys and we battle ALL the time. YAY for open source! Tks for the help guys... I thought about it on the drive home tonight and yeah I only need the one loop. I don't know what I was thinking Quote Link to comment https://forums.phpfreaks.com/topic/151843-solved-looping-help/#findComment-797462 Share on other sites More sharing options...
Maq Posted March 31, 2009 Share Posted March 31, 2009 Just got back to this forum didn't know this post would bring forth such a discussion HAHA. yeah I work in an evironment of open source guys and .NET guys and we battle ALL the time. YAY for open source! Tks for the help guys... I thought about it on the drive home tonight and yeah I only need the one loop. I don't know what I was thinking Haha yeah, gotta love the open vs closed source battles. Quote Link to comment https://forums.phpfreaks.com/topic/151843-solved-looping-help/#findComment-797467 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.