Jump to content

[SOLVED] another basic array question ..


zolen

Recommended Posts

Hello, have been trying to nut this out for a bit now, I am fairly sure its a syntax issue but then I am using the same logic to say that is I did to write the code .. which could also be completly wrong. (basically...I could be an idot ;D)

Anyhow let me show you the code:

$im_in_a_loop=0;
while($im_in_a_loop<5)//the actual script is much more complex but this should display the issue 
}
$im_in_a_loop++;
$im_an_array_in_a_loop = array($im_in_a_loop);
}

$array_reversed_out_of_loop = array_reverse($im_an_array_in_a_loop);
foreach($array_reversed_out_of_loop as $char)
echo $char;

//the answer I am looking for is 5 4 3 2 1

Link to comment
Share on other sites

wow thanks for the quick reply,  ;D

unfortunatly I do not have the option of changing how the variable enters the array but only how it exits hence the array_reverse. The reason I wrote it like that was to simplify a bit of code that is allready in use .. however the variable has simply been echoed within the loop, I need to put it into an array and reverse the order then echo/print.

Link to comment
Share on other sites

hehe .. well I cant seem to echo anything at the end. either the array isnt working or the reverse isnt working or the foreach isnt working ... was hoping that someone would see the code and say "OMG thats soo simple ... and tell me that I have put a . where a : should be .. or something like that  ::)

Link to comment
Share on other sites

Well, I think it's this line:

 

$im_an_array_in_a_loop = array($im_in_a_loop);

 

In which $im_an_array_in_a_loop is basically an array containing the first element only... If you want to keep adding more vales into the array, make it:

 

$im_an_array_in_a_loop[] = $im_in_a_loop;

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.