Skip to content

Instantly share code, notes, and snippets.

@norcross
Created April 21, 2014 14:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norcross/11145044 to your computer and use it in GitHub Desktop.
Save norcross/11145044 to your computer and use it in GitHub Desktop.
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