Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 分解一个分号字符串并从中分割出部分_Php_Arrays_Regex_Split_Php 5.5 - Fatal编程技术网

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。。。我不知道我是怎么错过的。我喜欢这个问题的标题是如何伪装成答案的。