Thread: fileorder?
View Single Post

  #10 (permalink)  
Old 10-02-2005
roN
 
Posts: n/a
Default Re: fileorder?

Stefan Rybacki wrote:

> roN wrote:
>> roN wrote:
>>
>>
>>>wouldn't a sort-algorithm like this work:
>>>function MySort($Array, $StringA)
>>>{
>>> $i=Array;
>>> for ($i=0; $i>=Array.size(); $i++)
>>> {
>>> while (strpos($Array[$i],$StringA))//if Array $i contains
>>> StringA,
>>> {
>>> move Element $i to $i+1; and
>>> move $i+1 to $i;
>>> }
>>> }
>>>}
>>>but how to move the elements?

>>
>>
>> Well, can't you help me anymore?

>
>
> I can.
>
> uksort is such a function, but you need usort.
>
> Use a compare function like this:
>
> function mycompare ($a, $b) {
> //first check for search text in $a and $b
> $isInA=(strpos($a,'test')!==false);
> $isInB=(strpos($b,'test')!==false);
>
> //so if $isInA==$isInB then compare alphabetical
> if ($isInA == $isInB) {
> if ($a == $b) return 0;
> return ($a > $b) ? 1 : -1;
> } else {
> //the one that is true comes first
> return ($isInA) ? -1:1;
> }
>
> return 0;
> }
>
> this function sorts entries with 'test' in it to the front and
> alphabetical in case of more than one entries containing this text or in
> case that there is no 'test' in that entry.
>
> use it like this:
>
> usort($PicArray,"mycompare");
>
> BTW: your commentaries are in german, may you better switch to english
> very soon


erm what commentaries?
and thank you very much for your help!
I think I'll get it done now :)
my array looks like this:
p1010001-05-09-03.jpg
p1010001-05-09-04.jpg
p1010001-05-09-05,06.jpg
p1010001-05-09-07,08,09.jpg
p1010001-05-09-12.jpg
p1010001-05-09-13,14.jpg
p1010001-rest.jpg
p1010002-05-09-03.jpg
p1010002-05-09-04.jpg
p1010002-05-09-05,06.jpg
p1010002-05-09-07,08,09.jpg
p1010002-05-09-12.jpg
p1010002-05-09-13,14.jpg
....
....
....
and i would like to sort it like this:
p1010001-05-09-03.jpg
p1010002-05-09-03.jpg
p1010001-05-09-04.jpg
p1010002-05-09-04.jpg
p1010001-05-09-05,06.jpg
p1010002-05-09-05,06.jpg
p1010001-05-09-07,08,09.jpg
p1010002-05-09-07,08,09.jpg
p1010001-05-09-12.jpg
p1010002-05-09-12.jpg
p1010001-05-09-13,14.jpg
p1010002-05-09-13,14.jpg
p1010001-rest.jpg
....
....
....

how do I have to manipulate the function you provided to do that?
Did you get the order by the way? first ordered by umber then by date...
Thank you again! :)
--
chEErs roN

I'm root, I'm allowed to do this! ;)
keep on rockin'
Reply With Quote