使用PHP如何打印字符串反向

1 php

我想打印字符串反转.我找到了这段代码,但我无法理解for循环后立即两行的含义是什么.

<?php 
    $s = 'abcdefg';
    $j = 0;

    for ($i = strlen($s) - 1; $i >= 0; $i--) {
       $s .= $s[$i];
       $s[$i] = NULL;
       $j++;
    }
    echo "$s";
    echo "<br/>";
    echo "there are " . $j . " character in the string.";
?>
Run Code Online (Sandbox Code Playgroud)

urf*_*ion 6

只需简单地使用 strrev

<?php
echo strrev("abcdefg");
Run Code Online (Sandbox Code Playgroud)