Jump to content

Help get an array outside of this loop?


bdflynn

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/266958-help-get-an-array-outside-of-this-loop/
Share on other sites

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.