用PHP替换数组中的数组 目标

用PHP替换数组中的数组 目标,php,arrays,Php,Arrays,替换此项: ( [0] => 'Header' [1] => 'Body' ) 为此: ['Header'] => Array ( [0] => Hello! ) ['Body'] => Array ( [0] => This is the body ) 问题 我缺少逻辑,我认为这是因为我不知道语法 情景 遵循原始阵列(预览): 代码: 结果是: Array ( [0

替换此项:

(
    [0] => 'Header'
    [1] => 'Body'
)
为此:

['Header'] => Array
    (
        [0] => Hello!
    )

['Body'] => Array
    (
        [0] => This is the body
    )
问题 我缺少逻辑,我认为这是因为我不知道语法

情景 遵循原始阵列(预览):

代码:

结果是:

Array
(
    [0] => 'Header'
    [1] => 'Body'
    ['Header'] => Array
        (
            [0] => Hello!
        )

    ['Body'] => Array
        (
            [0] => This is the body
        )

)

有人能给我一个主意吗?

要么这个,要么我不明白你在问什么

$origarr = array('header', 'body');

foreach($origarr as $value){
    if ($value == 'header'){
        $header['header'] = array('hello'); 
    }
    if ($value == 'body'){
        $body['body'] = array('This is the body'); 
    }   
}

var_dump($header);
var_dump($body);
你在找我。将两个数组传递给它,一个是键,另一个是值

$array['Section'] = array_combine($array['Section'], $this->contents);

也许这就是你想要的?也许。我只是不知道如何(技术上)在我的情况下应用它。什么是
$this->contents
$this->contents
['Hello','this is the body']
。我的错。然后你可以做
array\u组合($array['Section',$this->contents):-)P.S.
$mineredSection
不是已经是您想要的数组了吗?
Array
(
    [0] => 'Header'
    [1] => 'Body'
    ['Header'] => Array
        (
            [0] => Hello!
        )

    ['Body'] => Array
        (
            [0] => This is the body
        )

)
$origarr = array('header', 'body');

foreach($origarr as $value){
    if ($value == 'header'){
        $header['header'] = array('hello'); 
    }
    if ($value == 'body'){
        $body['body'] = array('This is the body'); 
    }   
}

var_dump($header);
var_dump($body);
$array['Section'] = array_combine($array['Section'], $this->contents);