Very simple loop array help

Reply

Join Date: Jul 2009
Posts: 27
Reputation: Toxikr3 is an unknown quantity at this point 
Solved Threads: 0
Toxikr3 Toxikr3 is offline Offline
Light Poster

Very simple loop array help

 
0
  #1
Oct 18th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,064
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 135
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster
 
0
  #2
Oct 18th, 2009
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??

  1. $start_no = 2;
  2. $end_no = 17;
  3.  
  4. // ... other code? ...
  5.  
  6. $i = $start_no;
  7. while($i <= $end_no){
  8.  
  9. // ... check the value here if you need to BEFORE adding the value ...
  10.  
  11. $myarray[] = $i;
  12.  
  13. // ... check the value here if you need AFTER adding the value ...
  14.  
  15. $i = $i + 1;
  16. }

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.
Happy Humbugging Christmas
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 27
Reputation: Toxikr3 is an unknown quantity at this point 
Solved Threads: 0
Toxikr3 Toxikr3 is offline Offline
Light Poster
 
0
  #3
Oct 18th, 2009
Wow thanks, thats pretty much what I needed ^_^

Sorry if you couldn't understand my question,

I will give this a go, thanks!

-Toxikr3
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC