448191 Posted January 15, 2008 Share Posted January 15, 2008 I suck at math. What I want is an array who's values are accumulatively repeated by some factor. I don't have a clue how to accomplish this. Quote Link to comment https://forums.phpfreaks.com/topic/86106-solved-accumulative-repetition/ Share on other sites More sharing options...
AndyB Posted January 15, 2008 Share Posted January 15, 2008 for ($i=0;$i<$max;$i++) { $arr[$i] = some_function(of $i, some factor, maybe $arr[$i-1], etc ???); } Seems too trivial to be the answer. Clue me in on 'accumulatively repeated'. Quote Link to comment https://forums.phpfreaks.com/topic/86106-solved-accumulative-repetition/#findComment-439768 Share on other sites More sharing options...
448191 Posted January 15, 2008 Author Share Posted January 15, 2008 As soon as you posted that, I realized I what I meant to say is I need exponential growth of repetition, not accumulative. So thanks for being confused <?php $array = array(); $base = 2; $fill = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'); for($i = 1; $i < count($fill); ++$i){ $array = array_merge($array, array_fill(0, pow($base, $i), current($fill))); next($fill); } var_dump($array); ?> I feel a bit stupid for not thinking of this right away. Anyway. Thanks for reading Quote Link to comment https://forums.phpfreaks.com/topic/86106-solved-accumulative-repetition/#findComment-439818 Share on other sites More sharing options...
Barand Posted January 15, 2008 Share Posted January 15, 2008 Don't forget to mark as "Solved" Quote Link to comment https://forums.phpfreaks.com/topic/86106-solved-accumulative-repetition/#findComment-440417 Share on other sites More sharing options...
448191 Posted January 16, 2008 Author Share Posted January 16, 2008 Good point. Done. Quote Link to comment https://forums.phpfreaks.com/topic/86106-solved-accumulative-repetition/#findComment-440654 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.