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

Recommended Answers

All 2 Replies

Member Avatar for diafol

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.

commented: Thanks for the help +1

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

Sorry if you couldn't understand my question,

I will give this a go, thanks!

-Toxikr3

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.