$version = way_to_get_version();print $version;would print 5.3.0 on one machine, và 5.3.1 on another machine.
Bạn đang xem: How to check the php version
However, for best practice, I would use the constant PHP_VERSION. No function overhead, and cleaner IMO.
Also, be sure to use version_compare() if you are comparing PHP versions for compatibility.
echo PHP_VERSION;constants are always faster then function calls.
Xem thêm: tên đẹp cho bé gái
To compare versions you should always rely on version_compare().
You may also be interested in function_exists()
$version = (float)phpversion();if ($version > 7.0) //do something for php7.1 và above. Elseif ($version === 7.0) //do something for php7.0 else //do something for php5.6 or lower.
Thanks for contributing an answer to lớn Stack Overflow!
But avoid …
Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.
By clicking “Post Your Answer”, you agree to lớn our terms of service, privacy policy and cookie policy
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.