Jump to content

Sort Array


shage

Recommended Posts

I am sorting on date of images which are the thumbnail of the tutorial, now i call the array doing the date, which gives me a long list of tutorials,  i would like to only list 2 from each day then a break with adver then list 2 more from another date etc, whats the best way to do this, right now it just lists all the tutorials in order well the first 7 but breaks for adver etc

Link to comment
https://forums.phpfreaks.com/topic/72959-sort-array/
Share on other sites

well i have a folder where images are named 20071010-photoshop-text1.jpg and the next 6 might be 20071010-photoshop-text(2-6).jpg

 

i want it to search the folder

 

image 1

image 2

adver

image 3

image 4

adver

image 5

image 6

 

see what im saying, right now i can post all them on the page but i have no breaks in the loop to apply adver

Link to comment
https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-368064
Share on other sites

well i have a folder where images are named 20071010-photoshop-text1.jpg and the next 6 might be 20071010-photoshop-text(2-6).jpg

 

i want it to search the folder

 

image 1

image 2

adver

image 3

image 4

adver

image 5

image 6

 

see what im saying, right now i can post all them on the page but i have no breaks in the loop to apply adver

 

Well, at last you have given us clue about the images, but there seems to be contradiction in this example and your earlier statement about only 2 from each day then an advert then 2 from the next day etc.

 

And where do the adverts come from? How are they stored?

Link to comment
https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-368085
Share on other sites

they are all in a folder in that folder list several other folders in which have the name of the tutorial, inside the folder in the thumb which has the date, right now i have it sort into date, it grabs them all i limited to 7 so it only pulls 7, just trying to think of a way to break after two for a advertisement

Link to comment
https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-368087
Share on other sites

you only need to count to 2

<?php
$images  = array ('a', 'b', 'c', 'd', 'e', 'f', 'g');  // your array of images.

$k = 0;           // counter

foreach ($images as $im)
{
    echo "<img src='$im'><br>";
    if (++$k == 2)
    {
        echo "advert here<br>";
        $k = 0;
    }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/72959-sort-array/#findComment-368217
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.