|
Posted by Brian on 03/28/07 00:18
"ZeldorBlat" <zeldorblat@gmail.com> wrote in message
news:1175021746.701819.274400@y80g2000hsf.googlegroups.com...
> On Mar 27, 12:21 pm, "Brian" <brian_no_s...@nrwp.co.uk> wrote:
>> Hi
>>
>> I'm sure there is a really easy way of doing this, but I just can't
>> seem to work it out.
>> I'm trying to use an array to create some more array which I
>> will then populate. It's going to be used to open up directory
>> and put of list of files in the array
>>
>> Here is the top array
>>
>> $galleries = array("array1" => "Descrption of 1", "array2" => "Descrption
>> of
>> 2", "array3" => "Descrption of 3");
>>
>> foreach($galleries as $k => $v){
>> // do some tests of directory if all OK then create an array
>>
>> $$k = array();
>>
>> // add to above array here
>>
>> }
>>
>> I am am trying to end up with is 3 arrays called 1 to 3.
>>
>> Thanks
>>
>> B
>>
> That code worked fine for me. What exactly is the problem you're
> having?
>
Hi ZeldorBlat
Below is the full code, I get an error saying
"Fatal error: Cannot use [] for reading in /var/www/...."
on this line, it will not add to the array?
$$k[] = $file; // add file to array
The idea is I will build up a set of arrays with the file list in them
which I will then use to create a show the photos in the gallery
$galleries = array("array1" => "Descrption of 1", "array2" => "Descrption of
2", "array3" => "Descrption of 3");
$path = '/var/www/..../';
foreach($galleries as $k => $v){ // Loop though each Key and Value in
gallery array
$gal_path = $path.$k; // make path to gallery
if ($handle = opendir($gal_path)) { // open path
$$k = array(); // make new array using the key as a
name
while (false !== ($file = readdir($handle))) {
if (is_file($k.'/'.$file)) { // check if is a file
$$k[] = $file; // add file to array
print "the file is $file<br>"; // print test line, remove later
}
}
closedir($handle);
sort($$k);
reset($$k);
} else {
print "<h3 align=center>$k Thumbnail Directory could not be opened,
sorry</h3>";
}
} // LOOP END foreach galleries
--------------------------------------------------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 1463 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
Navigation:
[Reply to this message]
|