How does PHP order an array? Are numbers > letters or vice versa?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pplers
    New Member
    • Apr 2007
    • 60

    How does PHP order an array? Are numbers > letters or vice versa?

    In an array, what's "bigger" ??

    "aaaa1111" or "aaaa" or "1111" or "1111aaaa" OR 'aaaa1111' or 'aaaa' or '1111' or '1111aaaa'

    Because i want to order an array, for example $arr = array('4wf', 'wf7u', '2345', '342gf', 'zzzzzzzzz', 'a', '999999999999', '1');
    The biggest value here is '999999999999' ???

    So, PHP orders NUMBERS first and then LETTERS ???
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Changed thread title to better describe the problem.

    Try using sort and see what happens.

    Alternatively, you could use usort to specify your own comparison function.

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      Originally posted by pplers
      In an array, what's "bigger" ??

      "aaaa1111" or "aaaa" or "1111" or "1111aaaa" OR 'aaaa1111' or 'aaaa' or '1111' or '1111aaaa'

      Because i want to order an array, for example $arr = array('4wf', 'wf7u', '2345', '342gf', 'zzzzzzzzz', 'a', '999999999999', '1');
      The biggest value here is '999999999999' ???

      So, PHP orders NUMBERS first and then LETTERS ???
      You could use usort along with one of the strcmp...() functions to choose which way you want things sorted.

      Comment

      Working...