mate64 mate64 - 1 year ago 98
PHP Question

How to sort versioning info

What's the right way, to handle versioning indicators like

2.4
or
2.4.0.9
etc. to get the ability of sorting versions.

PHP says, that
1.3.4
is not a valid integer, but also a non-valid number.

array('2.4','2.3.4','2.4.0.9')

Answer Source

PHP has a version_compare function. Use usort to sort it. Like following. :)

$a = array('2.4','2.3.4','2.4.0.9');
usort($a, 'version_compare');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download