我有一个代码,我必须使用“*”作为分隔符来分解我的文本。
我有一个模式,数组 [0] 和 [1] 总是被排除,其余的需要包含在变量中,但我的问题是我不知道如何动态捕获其余的我必须将它们全部放在其中的数组中。
特别是因为我的文本可能有更多“*”并分解成更多部分,但我必须将它们全部放在一起。排除[0]和[1]
$item= explode("*",$c7);
print_r($item);
//so now that I know which are my [0] and [1] arrays I need to get the rest of them inside of another variable
$variable = ?? //the rest of the $item arrays
最佳答案
$str = 'a*b*c*d*e';
$newStr = implode('*', array_slice(explode('*', $str), 2)); // OUTPUT: c*d*e
explode()用于通过分隔符对字符串进行分块
implode()用于从 block 中再次构建字符串
array_slice()用于选择元素范围
关于php - 如何获取数组范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39976641/