何时在PHP中使用字符串的递增运算符?

Hel*_*ano 5 php string increment operators decrement

我是第一次学习PHP,我发现该语言允许在字符串上使用递增运算符,这令人惊讶.

     $foo = 'xyZ';
     print ++$foo; // prints xzA
Run Code Online (Sandbox Code Playgroud)

我可以在这个主题周围找到的教程仅介绍玩具示例. 如果您提到使用此"功能"有益的情况,我将不胜感激.

提前致谢!

Bab*_*aba 4

I would be grateful if you mention a situation where using this 'feature' is beneficial.

这可能是一个非常有用的功能......

例子

$guess = "21661093e56e24cd60b10092005c4ac7";
$next = "aaaa";
$count = 0;
while(md5($next) !== $guess) {
    $next ++;
    $count ++;
}
printf("Found `%s` after %s loops", $next, number_format($count));
Run Code Online (Sandbox Code Playgroud)

输出

Found `baba` after 17,602 loops
Run Code Online (Sandbox Code Playgroud)

无论如何,我不打算很快破解任何 PIN 或密码