dyluck Posted January 9, 2010 Share Posted January 9, 2010 Hello, I don't know how to ask the question properly, but what code could I use to turn, for instance, the number 8 into array(1,1,1,1,1,1,1,1) (basicly, i need a foreach loop to cycle x times depending on the same x numerical value). does anyone know a super easy way to do this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/187800-how-would-i-make-array-follow-a-number/ Share on other sites More sharing options...
Alex Posted January 9, 2010 Share Posted January 9, 2010 Why don't you just use a for loop? Example: $loops = 8; for($i = 0;$i < $loops;$i++) { // ... } Quote Link to comment https://forums.phpfreaks.com/topic/187800-how-would-i-make-array-follow-a-number/#findComment-991572 Share on other sites More sharing options...
dyluck Posted January 9, 2010 Author Share Posted January 9, 2010 that worked perfectly! Just didn't know how to do it Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/187800-how-would-i-make-array-follow-a-number/#findComment-991574 Share on other sites More sharing options...
ignace Posted January 9, 2010 Share Posted January 9, 2010 Shorter: print_r(array_fill(0, 8, '1')); Quote Link to comment https://forums.phpfreaks.com/topic/187800-how-would-i-make-array-follow-a-number/#findComment-991662 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.