www.webdeveloper.com
Results 1 to 8 of 8

Thread: add $var's to new array

  1. #1
    Join Date
    Mar 2003
    Posts
    42

    add $var's to new array

    Hi, thanks for looking,

    ok a little bit of nfo before i get to my problem, there are images in 'images/' like so;

    39_images01.jpg
    39_images02.jpg
    40_you are crazy.jpg
    40_one-two.jpg

    ok so, i have the following code;

    PHP Code:
    function MainPic($GID) {
      
    $handle opendir("images");
      while (
    $file readdir($handle)) {
        if (
    $file != "." && $file != ".."){
          
    $array split("_",$file);
          if (
    $array[0] == $GID){
              echo (
    $file."<br>\n");
          }
        }
      }
      
    closedir($handle);


    so if you can imagine i call my function like;

    $GID="39";
    MainPic($GID);

    then im going to get a list of the images (from above)

    39_images01.jpg
    39_images02.jpg

    right? ... ok, so instead of echoing the files, i would like to put them into an array, because im going to use array_rand in the future to display a random image for the appropriate $GID call .. can any help me with this? I checked the array section on php.net and didnt see any examples of creating arrays with adding $file ..
    any ideas?

    Thanks a bunch,
    Al
    Last edited by Bungholio; 06-30-2003 at 04:54 PM.

  2. #2
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    You should use array_push() to append values to an array.

    [J]ona

  3. #3
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    You'll find a full list of array commands at http://us3.php.net/array, including array_push() as Jona mentioned, and array_unshift() to prepend values to the beginning of an array.

  4. #4
    Join Date
    Mar 2003
    Posts
    42
    thanks fellas

  5. #5
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Well, for what I did, you're welcome. (I'm not gonna speak for pyro, he knows too much as it is. )

    [J]ona

  6. #6
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    lol.. and I always feel bad saying "Your welcome" if I the help was mutually offered, as I feel like I'm saying to the other poster "Hey look, he said thank you, and it must have been to me..." That's just me, I guess... Anyway, for my part, you're welcome...

  7. #7
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Didn't mean to bring on the guilt...

    [J]ona

  8. #8
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    hehe... nope, no guilt. Just saying why I didn't acknowledge it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles