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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.