Professional Web Applications Themes

array data matches but array created in loop doesn't work - PHP Development

I have the exact same data in two arrays, but only the array created like so will work: $spaw_imglibs = array( array( 'value' => '/youth/pics/Member pics/', 'text' => 'Member pics', ), array( 'value' => '/youth/pics/Group pictures/', 'text' => 'Group pics', ), ); This array creates an exact copy of the array above: $spaw_imglibs = array(); $test= array(); $base = './pics/'; if(is_dir($base)){ $dh = opendir($base); while (false !== ($dir = readdir($dh))) { if (is_dir($base . $dir) && $dir !== '.' && $dir !== '..') { $subs = $dir ; $subbase = $base . $dir . '/'; $test[value]="/youth/pics/$dir/"; $test[text]="Subject: $dir"; array_push($spaw_imglibs,$test); } ...

  1. #1

    Default array data matches but array created in loop doesn't work

    I have the exact same data in two arrays, but only the array created
    like so will work:

    $spaw_imglibs = array(
    array(
    'value' => '/youth/pics/Member pics/',
    'text' => 'Member pics',
    ),
    array(
    'value' => '/youth/pics/Group pictures/',
    'text' => 'Group pics',
    ),
    );

    This array creates an exact copy of the array above:

    $spaw_imglibs = array();
    $test= array();
    $base = './pics/';
    if(is_dir($base)){
    $dh = opendir($base);
    while (false !== ($dir = readdir($dh))) {
    if (is_dir($base . $dir) && $dir !== '.' && $dir !== '..') {
    $subs = $dir ;
    $subbase = $base . $dir . '/';
    $test[value]="/youth/pics/$dir/";
    $test[text]="Subject: $dir";
    array_push($spaw_imglibs,$test);
    }
    }
    closedir($dh);
    }
    The code above just browses the directory tree of the server and fills
    in the same data as the first array, by finding the directory name and
    filling in $dir in the path. I would like to use this looped array
    because the directory tree will be expanding and I don't want to have
    to manually add to the array every time a new directory is created.


    I tested the arrays like so:
    $spaw_imglibs = array(
    array(
    'value' => '/youth/pics/Member pics/',
    'text' => 'Member pics',
    ),
    array(
    'value' => '/youth/pics/Group pictures/',
    'text' => 'Group pics',
    ),
    );

    They both display the same output, but the second array doesn't work
    for SPAW Editor version 1.0.3. The $spaw_imglibs array is used to
    store directories of images for this WYSIWYG editor. I can't tell why
    the 2nd array won't work, unless the syntax of
    $test[value]="/youth/pics/$dir/" somehow creates a different array
    from the syntax 'value'=>'/youth/pics/Member pics/'. The $dir
    variable holds exactly "Member pics", so it seems they would be the
    same. When I use the second array in SPAW, the image browser window
    comes up with no directories shown. The first array shows the two
    directories properly in the image browser.
    Could array_push be changing some structure of the array? Could PHP
    be converting the spaces into something weird that messes up SPAW?
    Any help will be greatly appreciated.
    Reed Law Guest

  2. #2

    Default Re: array data matches but array created in loop doesn't work

    anyone have an idea?
    Reed Law Guest

Similar Threads

  1. Question Check an array in a for-loop?
    By Unregistered in forum Brainstorming Area
    Replies: 0
    Last Post: October 4th, 08:31 PM
  2. loop through array to build a new array
    By pope on acid in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: April 22nd, 11:18 AM
  3. cannot loop the array
    By jrefactors@hotmail.com in forum Coldfusion - Getting Started
    Replies: 0
    Last Post: October 22nd, 07:02 PM
  4. Array Loop
    By CFRAM in forum Coldfusion - Advanced Techniques
    Replies: 2
    Last Post: July 28th, 06:03 AM
  5. loop and write array
    By Micah Montoy in forum PHP Development
    Replies: 0
    Last Post: August 3rd, 01:50 PM

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