【发布时间】:2021-03-15 09:28:29
【问题描述】:
我有一个像这样的常量类
Class MyConstants
{
const TEST = "asd";
const TEST123 = "foo";
const TEST333 = "fooBar";
const TEST321 = "bar";
}
在我的控制器中,我获取所有常量并随机选择 3,问题是我只从常量中获取密钥,但我需要值
$allConstants = $this->getAllConstants();
$foo = array_rand($allConstants, 3);
dd($foo)
array:3 [
0 => "TEST321"
1 => "TES"
2 => "TEST123"
]
我怎样才能得到常量的值,例如 foobar ?
然后我还需要将它们保存到数据库中。我应该循环它们吗?
$fooBarEntity->setData($foo);
感谢您的帮助。
【问题讨论】: