Bricktop Posted August 18, 2009 Share Posted August 18, 2009 Hi all, I'm trying to create a drop-down box of 0 to 100 percent using an array. The code I have is as follows: function percentage() { $numbers = range (0, 100); foreach($numbers as $number) { $content .= '<option value="'.$number.'">'.$number.'%</option>'; } echo $content; } I've never been too good with arrays so I've obviously made an error somewhere, could anyone tell me what I've done wrong please? Thanks Link to comment https://forums.phpfreaks.com/topic/170805-solved-simple-array/ Share on other sites More sharing options...
Bricktop Posted August 18, 2009 Author Share Posted August 18, 2009 Sorry, got it. Should have used foreach(range(0, 100) as $number) Link to comment https://forums.phpfreaks.com/topic/170805-solved-simple-array/#findComment-900797 Share on other sites More sharing options...
thebadbad Posted August 18, 2009 Share Posted August 18, 2009 Does $content exist before you call the function? If it does, you should pass it to the function, else initiate $content inside the function (to eliminate an "undefined variable" notice). And that change you made shouldn't make a difference. Link to comment https://forums.phpfreaks.com/topic/170805-solved-simple-array/#findComment-900798 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.