<span style="color: #0000ff"><span class="refname"># constant — <span class="dc-title">返回一个常量的值</span></span><br>interface</span><span style="color: #000000"> Test{ </span><span style="color: #0000ff">const</span> BAR = 'foobar'<span style="color: #000000">; } </span><span style="color: #0000ff">class</span><span style="color: #000000"> Foo{ </span><span style="color: #0000ff">const</span> BAR = 'foo_bar'<span style="color: #000000">; } </span><span style="color: #800080">$test</span> = 'BAR'<span style="color: #000000">; </span><span style="color: #0000ff">echo</span> <span style="color: #008080">constant</span>('Test::' . <span style="color: #800080">$test</span><span style="color: #000000">); </span><span style="color: #0000ff">echo</span> <span style="color: #ff00ff">PHP_EOL</span><span style="color: #000000">; </span><span style="color: #0000ff">echo</span> 'Foo::' . <span style="color: #800080">$test</span>;
参考地址:
以上是PHP中constant函数的使用的详细内容。更多信息请关注PHP中文网其他相关文章!