version_compare()は、二の"PHP標準"バージョン番 号文字列を比較します。この関数は、いくつかのバージョンのPHPでのみ 動作するプログラムを書きたい場合に有用です。
version_compare()は、最初のバージョンが2番目 よりも小さい場合に-1、等しい場合に0、2番目が小さい場合に+1を返し ます。
この関数はまず、バージョン文字列の _, - ,+をドット.で置き換えます。 さらに、数値でない部分の前後にドット.を追加します。 例えば'4.3.2RC1' は '4.3.2.RC.1'となります。 Then it splits the results like if you were using explode('.',$ver). Then it compares the parts starting from left to right. If a part contains special version strings these are handled in the following order: dev < alpha = a < beta = b < RC < pl. その後、explode('.',$ver)を使うのと同様に、結果を分割し、 左から右へパーツを比較してゆきます。 パーツが特別なバージョン文字列を含んでいる場合には、次のような順で 扱われます。 dev < alpha = a < beta = b < RC < pl。 This way not only versions with different levels like '4.1' and '4.1.2' can be compared but also any PHP specific version containing development state.
3番目のオプション引数operatorを指定した場 合、特定の関係を調べることが可能です。指定可能な演算子を以下に示 します。 <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne この引数を用いると、この関数はこの演算子により指定された関係が成 り立つ場合に1、そうでない場合に0を返します。