2
I was reading about version_compare()
of PHP.
Still, I didn’t understand much of the subject, could you explain a little more about?
2
I was reading about version_compare()
of PHP.
Still, I didn’t understand much of the subject, could you explain a little more about?
4
version_compare()
compares two versions, represented by strings, that are/are standardized by PHP.
version_compare($versao1 , $versao2);
The parameters to use the version_compare()
are quite simple:
if (version_compare(phpversion(), "4.3.0", ">=")) {
// versão do PHP maior que 4.3.0
} else {
// versão do PHP menor que 4.3.0
}
Operators that can be used are:
<, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne
.
When the operator is not used:
When using the operator:
TRUE
if the comparison is as specified by the operator, FALSE
otherwise.With standardized by PHP, I mean the fact that both must demonstrate the same format that is approved by PHP, for example:
version_compare('5.2', '5.2.0'); // -1
Will return -1
, for the 5.2.0
is not standardized in comparison.
However the same comparison, done better returns the expected:
version_compare('5.2.1', '5.2.0'); // 1
version_compare('5.2.0', '5.2.0'); // 0
version_compare('5.2.0', '5.2.1'); // -1
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.