| From | Sent On | Attachments |
|---|---|---|
| Phillip S. Baker | Jul 18, 2000 9:38 am | |
| Matt McClanahan | Jul 18, 2000 9:58 am | |
| Jon Parise | Jul 18, 2000 9:59 am |
| Subject: | Re: [PHP] Array Question | |
|---|---|---|
| From: | Matt McClanahan (card...@dodds.net) | |
| Date: | Jul 18, 2000 9:58:33 am | |
| List: | net.php.lists.php-general | |
On Tue, 18 Jul 2000, Phillip S. Baker wrote:
Okay I want to populate an array with a variable (i think that is the way to state it)
Ok ay I am using this code
$d = dir("images/"); while($entry=$d->read()) { if(($entry==".") OR ($entry=="..")) { echo ""; } else { echo $entry, "\n"; } } $d->close();
<snip>
How would I go about doing this in PHP 3 not PHP 4??
There really aren't very many version incompatibilities between PHP3 and PHP4. This will work in either case.
Since you can't predict how many images will be in the directory, or what their names will be, building the array in one step won't work unless you wanted to build up a delimited string and implode() it afterwards, which is just extra work. Fortunately, you can append to an array in a loop, which makes the task you want to accomplish quite simple.
$d = dir('images/'); while( $entry = $d->read() ) { if( ($entry != '.') AND ($entry != '..') ) $array[] = $entry; } $d->close();
When it finishes, you'll have $array with numerically keyed elements for each file in the directory.
Matt





