Convert a String into an Array of Characters

前端 未结 7 1268
陌清茗
陌清茗 2020-11-29 08:05

In PHP, how do I convert:

$result = "abdcef";

into an array that\'s:

$result[0] = a;
$result[1] = b;
$result[2] = c;         


        
7条回答
  •  青春惊慌失措
    2020-11-29 08:28

    best you should go for "str_split()", if there is need to manual Or basic programming,

        $string = "abcdef";
        $resultArr = [];
        $strLength = strlen($string);
        for ($i = 0; $i < $strLength; $i++) {
            $resultArr[$i] = $string[$i];
        }
        print_r($resultArr);
    

    Output:

    Array
    (
        [0] => a
        [1] => b
        [2] => c
        [3] => d
        [4] => e
        [5] => f
    )
    

提交回复
热议问题