1. First create a new PHP document and define a string, example:
$str = '百度经验作者:XCLBASE';
2. Use the built-in function strlen() to get the string length, example:
$strlen = strlen($str);
3. Define a for() loop. When $i<$strlen, execute it. Example:
for ($i=0; $i < $strlen ; $i++) { # code.. }
## 4. In the for() loop, print the string as an array, example:
for ($i=0; $i < $strlen ; $i++) { # code... echo $str[$i]; }
##5 , save the above content, view and print in the browser
Recommended tutorial:
The above is the detailed content of How to traverse output string in php. For more information, please follow other related articles on the PHP Chinese website!