Professional Web Applications Themes

Arrays within an array - PHP Development

Inherited a partially completed project that allows people to upload and download files to a website. Part of this involves posting a directory index with file names and a brief description of the file. Other information is recorded, but not posted. Data source is a text doent like this; ================= my_boring_pix.jpg Foo_Bar 127.0.0.1 Sunset_on_land my_exciting_pix.jpg Phu_Barr 127.0.0.2 Mountains_and_trees your_boring_pix.jpg Fu_Bah 127.0.0.3 Sunset_on_water your_exciting_pix.jpg Poo_Bear 127.0.0.4 Beaches_and_sand ================== An array of arrays seems to be the easiest way to provide sort and search functions. The array has been created and <print_r> shows this; ====================== Array ( [my_boring_pix.jpg] => Array ( [source] ...

  1. #1

    Default Arrays within an array

    Inherited a partially completed project that allows people to upload
    and download files to a website. Part of this involves posting a
    directory index with file names and a brief description of the file.
    Other information is recorded, but not posted.
    Data source is a text doent like this;
    =================
    my_boring_pix.jpg
    Foo_Bar
    127.0.0.1
    Sunset_on_land
    my_exciting_pix.jpg
    Phu_Barr
    127.0.0.2
    Mountains_and_trees
    your_boring_pix.jpg
    Fu_Bah
    127.0.0.3
    Sunset_on_water
    your_exciting_pix.jpg
    Poo_Bear
    127.0.0.4
    Beaches_and_sand
    ==================
    An array of arrays seems to be the easiest way to provide sort and
    search functions.
    The array has been created and <print_r> shows this;
    ======================
    Array
    (
    [my_boring_pix.jpg] => Array
    (
    [source] => Foo_Bar
    [ip_add] => 127.0.0.1
    [desc] => Sunset_on_land
    )

    [my_exciting_pix.jpg] => Array
    (
    [source] => Phu_Barr
    [ip_add] => 127.0.0.2
    [desc] => Mountains_and_trees
    )

    [your_boring_pix.jpg] => Array
    (
    [source] => Fu_Bah
    [ip_add] => 127.0.0.3
    [desc] => Sunset_on_land
    )

    [your_exciting_pix.jpg] => Array
    (
    [source] => Poo_Bear
    [ip_add] => 127.0.0.4
    [desc] => Beaches_and_sand
    )
    )
    ===============================
    This is exactly what I wanted.

    My problem is that I can't access the data in the array.
    It's embarrassing, and I'll blame it on burn-out.

    I'd assumed that something like;

    $data = $index_file [your_boring_pix.jpg][desc] ;

    would work but it doesn't.

    This is certainly a syntax issue and I'd appreciate it if someone
    could point me in the direction of a solution.

    Regards,

    CrossTalk




    Frank Guest

  2. #2

    Default Re: Arrays within an array

    Frank Rizzo wrote: 

    Don't forget the quotes!
    $data=$index_file['your_boring_pix.jpg']['desc']

    Should work.
    For traversal have a look at foreach.

    Regards
    Stefan
     
    Stefan Guest

  3. #3

    Default Re: Arrays within an array


    Stefan,

    Many thanks!

    Another case of overlooking the obvious.......


    On Sat, 23 Jul 2005 08:28:55 +0200, Stefan Rybacki
    <net> wrote:
     
    >
    >Don't forget the quotes!
    >$data=$index_file['your_boring_pix.jpg']['desc']
    >
    >Should work.
    >For traversal have a look at foreach.
    >
    >Regards
    >Stefan
    > [/ref]

    Frank Guest

Similar Threads

  1. Build multidimensional array from arrays
    By Kevin Old in forum PERL Beginners
    Replies: 5
    Last Post: January 29th, 07:47 PM
  2. array of arrays
    By Christiane Nerz in forum PERL Beginners
    Replies: 5
    Last Post: October 22nd, 06:26 PM
  3. Antwort: array of arrays
    By Manfred Beilfuss in forum PERL Beginners
    Replies: 0
    Last Post: October 20th, 10:54 AM
  4. += vs << when appending arrays to an array
    By Doug Beaver in forum Ruby
    Replies: 1
    Last Post: July 16th, 08:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139