PHP - iterate on string characters

前端 未结 9 853
失恋的感觉
失恋的感觉 2020-12-04 14:01

Is there a nice way to iterate on the characters of a string? I\'d like to be able to do foreach, array_map, array_walk, array_

9条回答
  •  离开以前
    2020-12-04 14:40

    Step 1: convert the string to an array using the str_split function

    $array = str_split($your_string);

    Step 2: loop through the newly created array

    foreach ($array as $char) {
     echo $char;
    }
    

    You can check the PHP docs for more information: str_split

提交回复
热议问题