bdflynn Posted August 11, 2012 Share Posted August 11, 2012 Hi all, I'm having some trouble getting an array from inside of a loop. Right now I am calling a function inside of a for() loop. The function returns an array into the variable $chunk. Obviously running the loop again causes $chunk to be written over with the next array. Ultimately each array is part of the same array, I need to merge them all into one in the end. $master_array = array(); for($i=1; $i<=$max_chunks; $i++){ $chunk = generate_chunk($i); // I realize this is not how it's done, this is essentially my last attempt which also failed. Didn't want anyone to think I wasn't trying. $master_array .= array_merge(array($chunk)); } var_dump($tile_info); Any ideas how I can get it out of the loop before the loop runs again? Cheers, D'Arcy Quote Link to comment https://forums.phpfreaks.com/topic/266958-help-get-an-array-outside-of-this-loop/ Share on other sites More sharing options...
MMDE Posted August 12, 2012 Share Posted August 12, 2012 Not exactly sure what you want, but what you are looking for might be this: $master_array[] = generate_chunk($i); or $master_array[$i] = generate_chunk($i); the first one will then be accessed from: $master_array[0] to $master_array[$max_chunks-1] the second: $master_array[1] to $master_array[$max_chunks] print_r($master_array); Quote Link to comment https://forums.phpfreaks.com/topic/266958-help-get-an-array-outside-of-this-loop/#findComment-1368698 Share on other sites More sharing options...
bdflynn Posted August 12, 2012 Author Share Posted August 12, 2012 Hey MMDE, I actually just figured it out as you posted! That was exactly what I needed. Thanks for the reply Quote Link to comment https://forums.phpfreaks.com/topic/266958-help-get-an-array-outside-of-this-loop/#findComment-1368705 Share on other sites More sharing options...
maxudaskin Posted August 12, 2012 Share Posted August 12, 2012 Quote Link to comment https://forums.phpfreaks.com/topic/266958-help-get-an-array-outside-of-this-loop/#findComment-1368715 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.