php爆炸所有角色

qwe*_*ymk 42 php arrays explode

我正在寻找相当于js 'this is a string'.split('')中PHP的内容.

如果我尝试$array = explode('', 'testing');我得到一个错误Warning: explode() [function.explode]: Empty delimiter in

还有另一种方法吗?

Jos*_*osh 98

如您的错误所示,explode需要使用分隔符来拆分字符串.str_split改为使用:

$arr = str_split('testing');
Run Code Online (Sandbox Code Playgroud)

产量

Array
(
    [0] => t
    [1] => e
    [2] => s
    [3] => t
    [4] => i
    [5] => n
    [6] => g
)
Run Code Online (Sandbox Code Playgroud)


nic*_*ckb 8

使用该str_split功能.

$array = str_split( 'testing');
Run Code Online (Sandbox Code Playgroud)


Mar*_*ach 5

$string = "TEST";

echo $string[0];  // This will display T
Run Code Online (Sandbox Code Playgroud)

没有必要爆炸它

  • 他的意思是说:“PHP 将像数组一样索引字符串”。但它不是数组,不能用于需要数组输入的函数。但是,您可以循环遍历字符串并使用与数组相同的符号提取单个字符,并在字符串的 `strlen` 上使用 `for` 循环。 (2认同)