0

Hi guys, I have a very simple question I can't solve because I haven't used arrays.

How can I make a For Loop that increments by 1 and when it does that takes the value and puts it in an array.

So eg.

Loop 1
Array = 1

Loop 2
Array = 2

etc..

I want to check in each loop after the value has been added to the array for a specific value.

Thats all I need. Hope you can help
-Toxikr3

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Toxikr3
1

I don't really understand what you're getting at. Have you checked the php online manual?

Could you give more specifics?

I want to check in each loop after the value has been added to the array for a specific value.

What value??

$start_no = 2;
$end_no = 17;
 
//  ... other code? ...

$i = $start_no;
while($i <= $end_no){

//   ... check the value here if you need to BEFORE adding the value ...

   $myarray[] = $i;

//   ... check the value here if you need AFTER adding the value ...

   $i = $i + 1;
}

This just adds the numbers 2-17 to the array variable, $myarray.

BTW: there is a short way of doing this, but the above should be easier to understand.

Votes + Comments
Thanks for the help
0

Wow thanks, thats pretty much what I needed ^_^

Sorry if you couldn't understand my question,

I will give this a go, thanks!

-Toxikr3

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.