note 109489 added to function.version-compare
| From: | mindplay.dk | Date: | Sat, 21 Jul 2012 03:10:38 +0000 |
| Subject: | note 109489 added to function.version-compare | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-189348@lists.php.net to get a copy of this message | ||
This little script can perhaps help you understand version comparison a little better - the output
is displayed in the comment at the top. Tweak the list of versions if you need more examples...
<?php
# 1 lt 1.0
# 1.0 lt 1.01
# 1.01 eq 1.1
# 1.1 lt 1.10
# 1.10 gt 1.10b
# 1.10b lt 1.10.0
header('Content-type: text/plain');
$versions = array(
'1',
'1.0',
'1.01',
'1.1',
'1.10',
'1.10b',
'1.10.0',
);
$comps = array(
-1 => 'lt',
0 => 'eq',
1 => 'gt'
);
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;
}
?>
----
Server IP: 192.41.42.26
Probable Submitter: 24.58.63.241
----
Manual Page -- http://www.php.net/manual/en/function.version-compare.php
Edit -- https://master.php.net/note/edit/109489
Del: integrated -- https://master.php.net/note/delete/109489/integrated
Del: useless -- https://master.php.net/note/delete/109489/useless
Del: bad code -- https://master.php.net/note/delete/109489/bad+code
Del: spam -- https://master.php.net/note/delete/109489/spam
Del: non-english -- https://master.php.net/note/delete/109489/non-english
Del: in docs -- https://master.php.net/note/delete/109489/in+docs
Del: other reasons-- https://master.php.net/note/delete/109489
Reject -- https://master.php.net/note/reject/109489
Search -- https://master.php.net/manage/user-notes.php