The goal
Replace this:
(
[0] => 'Header'
[1] => 'Body'
)
For this:
['Header'] => Array
(
[0] => Hello!
)
['Body'] => Array
(
[0] => This is the body
)
The problem
I'm missing the logic and I think this is happening because I doesn't know the syntax.
The scenario
Follow the original array (preview):
Array
(
[Title] => 'Hello!'
[Layout] => 'Shared/_Master'
[Section] => Array
(
[0] => 'Header'
[1] => 'Body'
)
)
Code:
<?php
$array = [
'Title' => 'Hello',
'Layout' => 'Shared/_Master',
'Section' => ['Header', 'Body']
];
$mineredSection = ['Header' => ['Hello!'], 'Body' => ['This is the body.']];
What did I already tried
I already tried this:
foreach ($array['Section'] as $index => $section) {
$t[$section] = [array_values(array_filter($mineredSection))[$index]];
}
$a = array_replace($array['Section'], $t);
print_r($a);
The result is:
Array
(
[0] => 'Header'
[1] => 'Body'
['Header'] => Array
(
[0] => Hello!
)
['Body'] => Array
(
[0] => This is the body
)
)
Can someone give me an idea?
array_combineis what you want?$this->contents?$this->contentsis['Hello', 'This is the body']. My bad.array_combine($array['Section'], $this->contents);:-) P.S. Isn't$mineredSectionalready the array you want?