Constructing Arrays with loops

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rhythmicimaging
Forum Newbie
Posts: 1
Joined: Fri Oct 25, 2002 7:09 am

Constructing Arrays with loops

Post by rhythmicimaging »

Hello

i'm fairly new to PHP. and i've got my head round using an array for the creation of a simple table of chapers.

While working on it i wondered if it would be possible to create an array with a loop, so the contents could be say, a1, a2, a3, a4, a5.

so what would happen is a loop would increment a variable ($i) by one every time till the condition was met. then each bit of data in the variable would be set from:-
a + $i

If this is possible, is there a more common name for the technique etc and more importantly is it possible?
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Basic Functions

Post by AVATAr »

You have to check basic things like for, while, foreach

Code: Select all

<?php
for ($i; $i<=5; i++)
   {
    $my_arrayї$i] = "a" . $i; 

   }
?>
hope it helps

PS: check array in the manual
Post Reply