Announcement

Collapse
No announcement yet.

manual sorting array

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • manual sorting array

    Hello,

    I am wonering if anyone can help me sort this array:

    PHP Code:
     Array
    (
        [
    0] => 52
        
    [1] => 51
        
    [2] => 1

    I want it to be like this 51, 52 , 1.

    I need them to be in order but I cant figure out how to do it.

    Thank in advance.
    Jon Whitcraft
    Internal Systems Engineer - SugarCRM

  • #2
    Do you mean you want them in an random order?

    Or Ordering them like 51,52,1 which isn't really possible unless you write a function that will do the greater number first but has the least value as the first digit.

    Comment


    • #3
      Originally posted by Andrew-ningc
      Do you mean you want them in an random order?

      Or Ordering them like 51,52,1 which isn't really possible unless you write a function that will do the greater number first but has the least value as the first digit.
      I got it figured out. I want it to look like the year has turned over. aka week 52 end of year and week 1 begining of year.
      Jon Whitcraft
      Internal Systems Engineer - SugarCRM

      Comment


      • #4
        I don't think it's possible to do it without another reference, like ... the year

        I mean, how could the script knows when to split the entries between "pre new year" and "post new year", if you have all the weeks of the year (1 to 52) in your array, how do you sort it ?
        Syntax errors in my post ? Well, I'm a french-speaking Swiss user..

        Comment


        • #5
          I ddin't realise you were on about week numbers, but as Symen_4ab pointed out, you need year identifer.

          My advise would be to store in the array as mktime(0,0,0, date('n'), date('d'), date('y')) which will return a load of numbers, put them in an array and using the sort() function, and to work out the week number you would do date('W', $array[n]) which will return a week number.

          See the date and mktime function if you are unsure of what each bit of code i said done.

          Comment


          • #6
            Acutally i am getting all of the numbers back from mysql and it was not returning them right. I was using %U and i should have been using %V and it worked great after i figured it out.

            Thanks for your input thought!!
            Jon Whitcraft
            Internal Systems Engineer - SugarCRM

            Comment

            widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
            Working...
            X