LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-30-2003, 10:17 PM   #1
niehls
Member
 
Registered: Jun 2002
Location: Sweden
Distribution: slack, redhat
Posts: 91

Rep: Reputation: 15
multidimensional array (php)


this is the first time i'm trying to play with a two-dimensional arry, so i might be completely wrong.
i have images in subfolders and i'm trying to get the into an array on the form:
$files[directory][file], but it's not working as expected.

this is the code:

PHP Code:
function get_all_images_on_server()
{
    
$handle=opendir(images);
    
        while(
$directory=readdir($handle))
        {
            if(!(
$directory==".." || $directory=="."))
            {
                if(
is_dir("images/$directory"))
                {
                    echo 
"now entering images/$directory<br>";
                    
                    
$new_handle=opendir("images/$directory");
                    
                                
$index=0;
                        while(
$file_in_sub_dir=readdir($new_handle))
                        {
                            if(!(
$file_in_sub_dir==".." || $file_in_sub_dir=="."))
                            {
                                echo 
"now inside...checking $file_in_sub_dir<br>";
    
    
                                        echo 
"trying to create variable files[$directory][$index]<br>";
                                    
$files = array ( "$directory"  => array ( "$index=> "$file_in_sub_dir"));

                                        echo 
"result: $files[$directory][$index]<br>";
                                    
$index++;

                            }
                        }
                }
            }
            
        }

as you can see i've entered some text to help me debug the code.
this is what is generated:
now entering images/lantliv
now inside...checking 11.jpg
trying to create variable files[lantliv][0]
result: Array[0]
now inside...checking 12.jpg
trying to create variable files[lantliv][1]
result: Array[1]
now inside...checking 13.jpg
trying to create variable files[lantliv][2]
result: Array[2]
now inside...checking 16.jpg
trying to create variable files[lantliv][3]
result: Array[3]
and so on...what is the problem. the result should be the filename...
help me please
 
Old 01-30-2003, 11:23 PM   #2
leed_25
Member
 
Registered: Jul 2002
Location: san francisco
Distribution: freebsd
Posts: 102

Rep: Reputation: 17
try adding another line to your php script like this:
Code:
echo "result: $files[$directory][$index]<br>";
var_dump($files[$directory][$index]);
does that clear it up for you?
 
Old 01-31-2003, 06:34 AM   #3
niehls
Member
 
Registered: Jun 2002
Location: Sweden
Distribution: slack, redhat
Posts: 91

Original Poster
Rep: Reputation: 15
hmm... if i remove the echo-line and add the var_dump line, the generated text is:
now entering images/lantliv
now inside...checking 11.jpg
trying to create variable files[lantliv][0]
string(6) "11.jpg" now inside...checking 12.jpg
trying to create variable files[lantliv][1]
string(6) "12.jpg" now inside...checking 13.jpg

how do i get only the filename???
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to allocate memory for a multidimensional array ? indian Programming 12 11-19-2004 04:37 AM
return index of element in java multidimensional array dave bean Programming 8 11-28-2003 12:00 PM
PHP array help? HappyDude Programming 1 10-13-2003 07:48 PM
PHP: Multidimensional array problem lhoff Programming 1 06-10-2002 03:49 PM
php array gui10 Programming 2 03-26-2002 03:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration