为什么 PHP 函数 strrev() 一会儿不起作用?

发布于 2024-10-05 17:19:08 字数 389 浏览 0 评论 0原文

我正在测试字符串上的一些 php 功能,但它不起作用。

这是我的代码:

$string = "L'eau est claire.";   
$string2 = explode(' ', $string);  

$count = count($string) - 1;  
while ($i <= $count)  
{   
  strrev($string2[$i]);  
  $i++;  
}

$string3 = implode (' ', $string2);  
echo $string3;   

我尝试了 strrev 函数,它确实有效。
你能给我一个线索吗?
非常感谢。
对不起英语,我是法国人。

I'm testing some php features on string but it doesn't work.

This is my code:

$string = "L'eau est claire.";   
$string2 = explode(' ', $string);  

$count = count($string) - 1;  
while ($i <= $count)  
{   
  strrev($string2[$i]);  
  $i++;  
}

$string3 = implode (' ', $string2);  
echo $string3;   

I tried the function strrev out the while and it does work.
Can you give me a clue?
Thanks a lot.
Sorry for the English, I'm French.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花细雨 2024-10-12 17:19:08

函数 strrev 不会修改中的字符串place - 它返回一个新字符串。在您的代码中,您没有使用 strrev 的结果 - 您正在调用该函数,然后丢弃结果。你需要在这里做一个作业:

$string2[$i] = strrev($string2[$i]);

The function strrev doesn't modify the string in place - it returns a new string. In your code you aren't using the result of strrev - you are calling the function and then discarding the result. You need an assignment here:

$string2[$i] = strrev($string2[$i]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文