PHP:字符串分割到数组中,就像没有分隔符爆炸 [英] PHP: Split string into array, like explode with no delimiter

查看:278
本文介绍了PHP:字符串分割到数组中,就像没有分隔符爆炸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串,如:


  

0123456789


和需要每个字符分割成一个数组。

我为它的地狱尝试:

 爆炸('','123545789');

但它给了我明显的:警告:没有定义分隔符爆炸) ..

我会怎么碰到过?我看不到任何方法了手,特别是只是一个函数


解决方案

  $阵列= str_split(0123456789bcdfghjkmnpqrstvwxyz);

str_split还需要第二个参数,该块长度,所以你可以做这样的事情:

  $阵列= str_split(AABBCCDD,2);// $数组[0] = AA
// $阵列[1] = BB
// $阵列[2] = CC等..

您还可以通过将其作为一个数组得到你的字符串的部分:

  $字符串=你好;
回声$字符串[1];//输出E

I have a string such as:

"0123456789"

and need to split EACH character into an array.

I for the hell of it tried:

explode('', '123545789');

But it gave me the obvious: Warning: No delimiter defined in explode) ..

How would I come across this? I can't see any method off hand, especially just a function

解决方案

$array = str_split("0123456789bcdfghjkmnpqrstvwxyz");

str_split also takes a 2nd param, the chunk length, so you can do things like:

$array = str_split("aabbccdd",2);

// $array[0] = aa
// $array[1] = bb
// $array[2] = cc  etc ...

You can also get at parts of your string by treating it as an array:

$string = "hello";
echo $string[1];

// outputs "e"

这篇关于PHP:字符串分割到数组中,就像没有分隔符爆炸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆