note 72709 deleted from function.usort by danbrown

From: Date: Sun, 23 Jan 2011 16:26:21 +0000
Subject: note 72709 deleted from function.usort by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176065@lists.php.net to get a copy of this message
Note Submitter: rob at digital-crocus dot com ---- To svenxy AT nospam gmx net A faster and clearer way of sorting IP addresses: <?php $zones = array('192.168.11', '192.169.12', '192.168.13', '192.167.14', '192.168.15', '122.168.16', '192.168.17' ); function sort_subnets_ip2long($a, $b) { return sprintf("%u", ip2long($a)) - sprintf("%u", ip2long($b)); } usort($zones, "sort_subnets_ip2long"); ?> Simple testing shows this version is just under twice as fast. MySQLers: No need to sort this stuff in PHP! Use MySQL's INET_ATON() family of functions to save cycles. var_dump($zones);

« previous php.notes (#176065) next »