我有一系列用於應用程序的常量字符串,它們放置在我的 config 目錄中名為 gameconstants 的文件中
我正在使用 config() 函數來獲取各種消息,因此該文件看起來與此類似
return [
'furiouspunches' => ' furiously punches ',
'kick' => ' kicks $loser in the junk ',
有沒有辦法讓我訪問 $loser 變量?我正在使用這些常量為我正在構建的應用程序返回字符串,所以我最終連接了這個返回值,最終輸出類似於
$winner . config('gameconstants.kick') . $loser
但是字符串並不總是以這種方式播放,所以我想訪問該變量,以便我可以返回該字符串的不同變體。
我試過了
config('gameconstants.kick.$loser') 但這不起作用。有什麼想法嗎?
提前致謝。
您將需要使用字符串替換,例如
return [
'furiouspunches' => ' furiously punches ',
'kick' => ' kicks {loser} in the junk ',
然後
$string = $winner . str_replace('{loser}', $loser, config('gameconstants.kick'))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句