Laravel每个登录会话请求一个单词的数字位置

时间:2018-02-03 20:45:40

标签: laravel laravel-5

在laravel中可以从单词中的数字中找到一个位置并使其随机化?

实施例

Secret Word= haveaniceday

Laravel现在请求例如来自y

的单词的最后一位数字
Whats the 12th digit from your word? Enter in text field

如果我输入y并且它的真实重定向。

我已经尝试使用strpos,但他们无法在每个会话中选择一个新的数字。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

你可以做到

//An example of session declaration
session()->put('position', 12);
session()->put('string', "haveaniceday");

//Fetch the stored data from the session
$position = session('position');
$string = session('string');

//Get the twelfthcCharacter 
$twelfthCharacter = $string[$position];

阅读documentation