I have the following two things:
- $_POST array with posted data
$params array with a path for each param in the desired data array.
$_POST = array( 'name' => 'Marcus', 'published' => 'Today', 'url' => 'http:://example.com', 'layout' => 'Some info...', ); $params = array( 'name' => 'Invoice.name', 'published' => 'Page.published', 'url' => 'Page.Data.url', 'layout' => 'Page.Data.layout', );
I would like to generate the $data array like the example below. How can I do that? Notice how the "paths" from the $params array are used to build the keys for the data array, filling it with the data from the $_POST array.
$data = array(
'User' => array(
'name' => 'Marcus',
),
'Page' => array(
'published' => 'Today',
'Data' => array(
'url' => 'http:://example.com',
'layout' => 'Some info...',
),
),
);