开发者

Why strrev() php function doesn't work in a while?

开发者 https://www.devze.com 2023-01-28 20:06 出处:网络
I\'m testing some php features on string but it doesn\'t work. 开发者_JAVA技巧 This is my code: $string = \"L\'eau est claire.\";

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

开发者_JAVA技巧

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.


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]);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号