note 94337 added to function.version-compare
| From: | meitarm at gmail dot com | Date: | Thu, 29 Oct 2009 09:47:08 +0000 |
| Subject: | note 94337 added to function.version-compare | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162232@lists.php.net to get a copy of this message | ||
Not knowing this function existed, I wrote my own implementation of something similar. Mine differs
from version_compare() in that it treats '1' as being equivalent to '1.0'.
Perhaps that might be useful to someone. The full code I wrote is here:
http://pastebin.com/f15172145
But here are the function signatures.
<?php
/**
* Compares two arbitrary version strings.
*
* @param mixed $ver The version to test. Can be a string or array created with parse_version().
* @param string $op The comparison operation to perform.
* @param mixed $num The version number to test the comparison again. Can also be a string or array.
* @return mixed True or false if comparison is performed, otherwise returns an array of the
passed-in version.
*
* @see parse_version(string $str, bool $named)
*/
function test_version ($ver, $op, $num)
// ...
/**
* Parses a version number string into an array.
*
* @param string $str The version number to parse.
* @param bool $named If true, adds extra elements to the array named "major,"
"minor," and "patch" for ease of use. Default is false.
* @return array An object whose elements correspond to the dot-seperated version numbers.
*/
function parse_version ($str, $named = false)
?>
----
Server IP: 69.147.83.197
Probable Submitter: 71.202.45.31
----
Manual Page -- http://www.php.net/manual/en/function.version-compare.php
Edit -- https://master.php.net/note/edit/94337
Del: integrated -- https://master.php.net/note/delete/94337/integrated
Del: useless -- https://master.php.net/note/delete/94337/useless
Del: bad code -- https://master.php.net/note/delete/94337/bad+code
Del: spam -- https://master.php.net/note/delete/94337/spam
Del: non-english -- https://master.php.net/note/delete/94337/non-english
Del: in docs -- https://master.php.net/note/delete/94337/in+docs
Del: other reasons-- https://master.php.net/note/delete/94337
Reject -- https://master.php.net/note/reject/94337
Search -- https://master.php.net/manage/user-notes.php