Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
quick example of how version_compare works
<?php
header('Content-type: text/plain');
$versions = array(
'1',
'1.0',
'1.01',
'1.1',
'1.1.0',
'1.1.1b',
'1.1.1',
'1.10',
'1.10b',
'1.10.0',
);
$comps = array(
-1 => '(below)',
0 => '(equal)',
1 => '(above)'
);
foreach ( $versions as $version ) {
if ( isset( $last ) ) {
$comp = version_compare( $last, $version );
echo str_pad( $last, 8, ' ', STR_PAD_LEFT ) . " {$comps[$comp]} {$version}\n";
}
$last = $version;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment