hp1 Posted July 28, 2010 Share Posted July 28, 2010 Hi,Been ages since I fiddled with one of my sites. Its a simple gallery that shows thumbnails as subsets of 5 images that can be scrolled through 5 at a time.I've managed to read all of the images in the directory into an array stripping out . and .. but now I'd like to iterate through that array taking each 5 images into a new array something like $imagearray= array(image1, image2.........image 10)some code here that give me.....$sub1=array(image1, image2.....image5);$sub2=array(image6, image7.....image10); This will the allow me to use the images in groups of 5.I suspect this is easier than I think it is, i just cant figure it....Appreciate any tips.cheers Link to comment Share on other sites More sharing options...
thescientist Posted July 28, 2010 Share Posted July 28, 2010 seems like a for loop would work pretty well. what have you got and/or tried? Link to comment Share on other sites More sharing options...
hp1 Posted July 28, 2010 Author Share Posted July 28, 2010 Shamefully I have nothing for this little problem other than existing array thats holding all the images. Needing a loop was about as far as i'd got.... I cant figure out the code that will then slice that array up into 5s into separate smaller arrays. Link to comment Share on other sites More sharing options...
justsomeguy Posted July 28, 2010 Share Posted July 28, 2010 You can use array_chunk to return an array of smaller arrays:http://www.php.net/manual/en/function.array-chunk.phpe.g.: $groups = array_chunk($images, 5);echo count($groups) . ' groups of images';for ($i = 0; $i < count($groups); $i++){ print_r($groups[$i]);} You can also use array_slice to get a piece of an array:http://www.php.net/manual/en/function.array-slice.php Link to comment Share on other sites More sharing options...
hp1 Posted July 29, 2010 Author Share Posted July 29, 2010 Cheers I'll have a play with these two functions. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.