Connecting Tech Pros Worldwide Forums | Help | Site Map

Sorting an array of IPAdresses

Newbie
 
Join Date: Jan 2008
Posts: 13
#1: Apr 10 '08
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

Newbie
 
Join Date: Mar 2008
Posts: 21
#2: Apr 10 '08

re: Sorting an array of IPAdresses


Hey

The following code should work:

[PHP]<?php


$ips = array("192.168.35.12", "192.168.230.112", "192.232.140.6", "192.168.116.34");


natsort($ips);


print_r($ips);

?>[/PHP]

Hope that helps.
Newbie
 
Join Date: Jan 2008
Posts: 13
#3: Apr 10 '08

re: Sorting an array of IPAdresses


Quote:

Originally Posted by gearoid

Hey

The following code should work:

[PHP]<?php


$ips = array("192.168.35.12", "192.168.230.112", "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
Newbie
 
Join Date: Mar 2008
Posts: 21
#4: Apr 10 '08

re: Sorting an array of IPAdresses


Quote:

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]
Reply