Jump to content

Help needed with Array! Shuffle


neil01

Recommended Posts

Hi there and thanks for reading.

 

I have the following problem/question:

I have a photo web site with different galleries. I wish to be able to re-sort the appearance of the photos so everything looks different and more dynamic , say on a daily or even weekly basis.

 

I have written a routine in VBA which basically takes the images... puts them in a temp folder, writes to an array, sorts the array using a random sqequence and then rewites the files back to the original folder. Hope you understand? So 1.jpg may now become 6.jpg etc (also 1thumbnail.jpg will also become 6thumbnail.jpg, and the same with 1.txt -> 6.txt) It is important that that what was previously 1.jpg remains linked with 1thumbnail and 1.txt! I'm sure you understand.

I then upload the images/texts again to the server.

 

I would now like to try this in php, but am relatively new to this, my only experience has been taking wordpress themes apart :(

 

If someone could point me in the right direction with arrays, shuffle etc in particular applying the same shulffle to the other folders i.e. thumbnails and texts i would be grateful.

 

Thanking you in advance and best wishes

Neil

Link to comment
Share on other sites

//path to folder where images are stored
$path = 'images1/'; 

//Store each set of pictures to it's respectiv array
$images1 = array('pic1.png','pic2.png','pic3.png');

//Shuffle each of the arrays
shuffle ($images1);

//Generate a random picture from the shuffle
$img1 = $path.$images1[rand(0, count($images1) - 1)];

After you've done the above you just simply echo it such as

<img src="<?php echo "$img1"; ?>" alt="Random picture">

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.