Php 分解一个分号字符串并从中分割出部分
我所拥有的是Php 分解一个分号字符串并从中分割出部分,php,arrays,regex,split,php-5.5,Php,Arrays,Regex,Split,Php 5.5,我所拥有的是 $string = 'one;two;three;four;five;six;seven;eight;nine;ten'; 我需要的是: $array = [ ['one', 'two', 'three'], ['four', 'five', 'six'], ['seven', 'eight', 'nine'], ['ten'], ]; 基本上,字符串可以有无限的值。可以使用数组\u chunk函数: $string = 'one;two;three;f
$string = 'one;two;three;four;five;six;seven;eight;nine;ten';
我需要的是:
$array = [
['one', 'two', 'three'],
['four', 'five', 'six'],
['seven', 'eight', 'nine'],
['ten'],
];
基本上,字符串可以有无限的值。可以使用
数组\u chunk
函数:
$string = 'one;two;three;four;five;six;seven;eight;nine;ten';
$array = array_chunk(explode(';', $string), 3);
总是三人一组?你不知道PHP有一个?现在你知道了。Argg。。。我不知道我是怎么错过的。我喜欢这个问题的标题是如何伪装成答案的。