foreverhex Posted December 27, 2007 Share Posted December 27, 2007 I don't know if this is possible. It sounds like it should be. Hopefully I can explain, but here I go: I have an array that is combined with varibles that say either 1 or 0 (true or false). What I want to do if possible, is take that array, everytime the arrays value = 1 ($array[0] = 1) show a script. Which will be a while loop also to handle some mysql arrays. My main goal is so I don't have to copy paste the while script over and over. Thanks for any help! Quote Link to comment https://forums.phpfreaks.com/topic/83362-solved-looping-arrays/ Share on other sites More sharing options...
blackcell Posted December 27, 2007 Share Posted December 27, 2007 To me it sounds like your having a problem cycling through your array. Is that your main issue? If so try something like: $arrayCount = count($array); $X = 0; while($X <= $arrayCount){ if($array[$X] == 1){ //Conduct your test for 1 or 0 here and run your while loop here if satisfied. } $countX++; } Quote Link to comment https://forums.phpfreaks.com/topic/83362-solved-looping-arrays/#findComment-424112 Share on other sites More sharing options...
foreverhex Posted December 27, 2007 Author Share Posted December 27, 2007 That seems like it would work, I see I needed to loops running. And yes I was having problems cycling the array. I'll give it a try and let you know. Quote Link to comment https://forums.phpfreaks.com/topic/83362-solved-looping-arrays/#findComment-424122 Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 You may want to look at the FOREACH function for arrays. Quote Link to comment https://forums.phpfreaks.com/topic/83362-solved-looping-arrays/#findComment-424131 Share on other sites More sharing options...
kenrbnsn Posted December 27, 2007 Share Posted December 27, 2007 There are a number of ways in PHP to loop through arrays "for","foreach","while" come to mind. "for" example: <?php for ($i = 0;$i < count($array);$i++) { // // do the work // } ?> "foreach" example: <?php foreach ($array as $ind => $val) { // // do the work // } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/83362-solved-looping-arrays/#findComment-424132 Share on other sites More sharing options...
foreverhex Posted December 27, 2007 Author Share Posted December 27, 2007 The foreach loop looks cleaner, but I just got the while loop to work that blackcell suggested. I don't want to touch it, it may break, lol. Thanks for all your help! Quote Link to comment https://forums.phpfreaks.com/topic/83362-solved-looping-arrays/#findComment-424265 Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 Copy and paste your code into a new page, then play with foreach, it's nice to know your options. Quote Link to comment https://forums.phpfreaks.com/topic/83362-solved-looping-arrays/#findComment-424268 Share on other sites More sharing options...
blackcell Posted February 9, 2008 Share Posted February 9, 2008 Yes it is always good for growth and intellectual expansion to copy/paste into a new page and figure out how to do it another way. Quote Link to comment https://forums.phpfreaks.com/topic/83362-solved-looping-arrays/#findComment-462645 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.