Sorting an array of IPAdresses

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ksn2007
    New Member
    • Jan 2008
    • 13

    Sorting an array of IPAdresses

    Hi All,

    I have to sort the array which containing IPaddresses I tried array_multisort ($iparray, SORT_ASC, SORT_STRING);

    but it is not working.Please suggest me the solution.

    Thanks,
    KSN
  • gearoid
    New Member
    • Mar 2008
    • 21

    #2
    Hey

    The following code should work:

    [PHP]<?php


    $ips = array("192.168. 35.12", "192.168.230.11 2", "192.232.140.6" , "192.168.116.34 ");


    natsort($ips);


    print_r($ips);

    ?>[/PHP]

    Hope that helps.

    Comment

    • ksn2007
      New Member
      • Jan 2008
      • 13

      #3
      Originally posted by gearoid
      Hey

      The following code should work:

      [PHP]<?php


      $ips = array("192.168. 35.12", "192.168.230.11 2", "192.232.140.6" , "192.168.116.34 ");


      natsort($ips);


      print_r($ips);

      ?>[/PHP]

      Hope that helps.
      Thank You,
      Is there any function to get them in descending order,of course we can write some code to display the result of natsort($ips) in reverse order but I wonder is there any function to get the IPs in descending order
      Thanks,
      KSN
      Last edited by ksn2007; Apr 10 '08, 01:45 PM. Reason: miss spell

      Comment

      • gearoid
        New Member
        • Mar 2008
        • 21

        #4
        Originally posted by ksn2007
        Thank You,
        Is there any function to get them in descending order,of course we can write some code to display the result of natsort($ips) in reverse order but I wonder is there any function to get the IPs in descending order
        Thanks,
        KSN
        Not as far as I know I'm afraid.

        However, just use the following code to get descending order:

        [PHP]<?php

        $ipsDesc = array_reverse($ ips);

        ?>[/PHP]

        Comment

        Working...