我正在寻找一个将参数传递给动态常量Name的解决方案.
<?php
class L {
const profile_tag_1 = 'Bla bla Age from %s to %s';
const profile_tag_2 = 'Wow Wow Age from %s to %s';
public static function __callStatic($string, $args) {
return vsprintf(constant("self::" . $string), $args);
}
}
Run Code Online (Sandbox Code Playgroud)
我的代码
$x = 1;
echo constant("L::profile_tag_".$x); // arguments: 20, 30
Run Code Online (Sandbox Code Playgroud)
我想得到
Bla bla Age from 20 to 30
Run Code Online (Sandbox Code Playgroud)
我怎样才能将我的两个论点传递给它?
php ×1