www.webdeveloper.com
Results 1 to 2 of 2

Thread: random file name

  1. #1
    Join Date
    Sep 2008
    Posts
    206

    random file name

    now i am getting all images in a file using the function glob
    PHP Code:
    $files glob("../images/gallery/".$x."thumbnails/*.jpg"
    after that i store it in an array
    PHP Code:
     foreach ($files as $value
    all that i need is to make the $value to produce random value from the array produced by foreach function...

    when i echo the image i want it to be random.. thats all that i need

  2. #2
    Join Date
    Nov 2008
    Posts
    2,477
    Glob already returns an array so I'm not sure what you mean by "after that I store it in an array". If you just want to get a random item from the array you can use array_rand:

    PHP Code:
    $files glob("../images/gallery/".$x."thumbnails/*.jpg");
    echo 
    $files[array_rand($files)]; 
    If you are doing this in a loop, I would do something like:

    PHP Code:
    $files glob("../images/gallery/".$x."thumbnails/*.jpg");
    shuffle($files);
    foreach (
    $files as $file) {
        
    //...


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