Re: Sorting IP Address Data
| From: | Tom Rogers | Date: | Thu, 23 Aug 2001 09:41:54 +0000 |
| Subject: | Re: Sorting IP Address Data | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-64073@lists.php.net to get a copy of this message | ||
one solution that works on all ip numbers
<?
$ip = array("192.168.132.3","192.168.132.2","0.0.0.1","192.168.132.4","192.168.1.1","192.168.0.1");
foreach($ip as $val){
$split = explode(".",$val);
$num = (16777216 * $split[0]) + (65536 * $split[1]) + (256 * $split[2]) + $split[3];
$iplist["$num"] = $val; //quotes needed to force it into assoc type array (php4.0.4)
}
ksort($iplist,SORT_NUMERIC );
reset($iplist);
foreach($iplist as $val){
echo $val."<br>";} ?> At 01:28 PM 23/08/01, Chris Aitken wrote:
Hi all, Just a quick one, I am pulling a whole Class C list of IP addresses, and im trying to sort them in order, but im getting it displayed 127.0.0.1 127.0.0.10 127.0.0.100 127.0.0.101 127.0.0.102 etc. Is there any other way to sort this thinking they are numbers, rather than text ? Thanks Chris --Chris Aitken - Administration/Database Designer - IDEAL Internetemail: chris@ideal.net.au phone: +61 2 4628 8888 fax: +61 2 4628 8890__-----------------------------------------__ *** Big Brother ***It just shows that the dull will rule the world. And we will be watching it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net