version_compare issues on patch version
echo version_compare("1.0", "1.0.0", '<');
return true;
both version are same why getting true,
any one solution please.
This is by design. See the comments on the doc page and closed bugs.
It may not be intuitive, but it is the intended behavior. The function splits each string into chunks delineated by dots, and then compares each chunk from left to right. So 1.0
essentially gives you parts 1, 0, null
while 1.0.0
gives you parts 1, 0, 0
. So the comparison eventually works out to null comparing to zero, which PHP considers to be “less than.”
If you want to consider “1.0” to be the same as “1.0.0” then you’ll need to make sure each string is zero-padded out to the same number of sections.