Jump to content

sort images in php with array


pooker

Recommended Posts

I use an array to store multiple image files.  I want to sort them according to there numeric value some are named like this

 

series001.jpg

series002.jpg

 

The sort function does not work though if I type

 

sort($img);  ///the array name is $img

 

It does not sort them and does not even return a value, this same technique works with sorting folders of the same name but not of images it appears.

Link to comment
https://forums.phpfreaks.com/topic/114397-sort-images-in-php-with-array/
Share on other sites

hi....

 

i have used following code:

 

$img = array("series222.jpg", "series002.jpg", "series012.jpg" , "series001.jpg", "series003.jpg", "series102.jpg", );

sort($img);

print "<pre>";

print_r($img);

 

and it is sorting perfectly

 

Array

(

    [0] => series001.jpg

    [1] => series002.jpg

    [2] => series003.jpg

    [3] => series012.jpg

    [4] => series102.jpg

    [5] => series222.jpg

)

echo  "<img src=\"./mangareader/$series/$chapter1/$img[$number]\" >";

 

There is my code for calling the image

 

when I just leave it lik that, without

 

sort($img); it works perfectly fine, except for being out of order. 

 

The minute I put the above code in it acts like nothing is even there, you can click on view image sourc and it acts like it never read the array.

no from count function and readdir.  The $img array runs a loop and stores each name from the readdir which works perfectly.  Then it uses a count function and get action to tell you what page number you are on and stores that in $number, which works perfectly.  It always shows up the correct amount of images and everything except for them being out of order, then when I try to sort them nothing happens.  It treats it like its not an array or something, but I did this same thing just with folders and it worked perfect on my other script.

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.