将Array添加到数组PHP中

时间:2017-03-03 03:50:11

标签: php arrays

假设我有一组字符串,其中包含字符的分隔符,我如何将其作为数组添加到数组中?

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)
)

1 个答案:

答案 0 :(得分:1)

foreach ($parts as $part){
    $this->fileTextHeaders[] = [$part];
}