假设我有一组字符串,其中包含字符的分隔符,我如何将其作为数组添加到数组中?
private fileTextHeaders = array();
public function addHeaders($longStringHeaders){
$parts = explode("@", $longStringHeaders);
foreach ($parts as $part){
$this->fileTextHeaders[] = $part;
}
print_r($this->fileTextHeaders);
}
我有以下代码,但结果是
addHeaders("test@yes@no");
array ([0]=>test, [1]=>yes, [2]=no)
我的目标是
array(
array(test),
array(yes),
array(no)
)
答案 0 :(得分:1)
foreach ($parts as $part){
$this->fileTextHeaders[] = [$part];
}