Jump to content

Recommended Posts

Posted

Working on a new pet project, I have a segment that's split into 3 images. I want those images to be picked at random.

 

However, I also have some fancy shenanigans where you hover over an image and get some information about it, using extra divs and div:hover CSS. So obviously, I want the image and the information to be paired up, so it doesn't - for example - pick image A and context F. 

 

I'm prety sure 

$images=array(
'image1.jpg' => 'Image title<br>by <a href="url">Some Guy</a>',
'image2.jpg' => 'Image title<br>by <a href="url">Some Other Guy</a>',
'image3.jpg' => 'Image title<br>by <a href="url">Yet Another Guy</a>'
);

is the right way of doing the array in pairs?

 

But then I'm struggling to pick at random. I've tried multiple variants of array_rand and shuffle($images) + array_slice but I'm entirely open to the idea that I just don't know how to format it properly because PHP is still pretty new to me.

 

The idea is that I get it to pull 3 random strings and splice that into html using php echo, e.g. 

<div id="galleryimg">
	<img src="../img/gallery/<?php echo $rand_images1[0]; ?>">
	<div class="contextoverlay">
		<div class="contexttext">
			<center><?php echo $rand_images1[1]; ?></center>
		</div>
	</div>
</div>

 

Maybe that's not the right way to handle it? 

 

Any help would be appreciated!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...