foreach ($array['pt_doc_title'] as $key => $title) {
$id = isset($array['pt_doc_id'][$key]) ? $array['pt_doc_id'][$key] : null;
$file = isset($array['pt_doc_file_iname'][$key]) ? $array['pt_doc_file_iname'][$key] : null;
$array['pt_documents_data'][] = array(
'pt_doc_title' => $title,
'pt_doc_id' => $id,
'pt_doc_file_iname' => $file
);
}
unset($array['pt_doc_title'], $array['pt_doc_id'], $array['pt_doc_file_iname']);
Something along these lines. You use the keys of $array['pt_doc_title']
to get the corresponding other two values from the other two arrays, then you group them into a new array pt_documents_data
.
For a simplified example of the general operation:
$array = array(
'foo' => array('a', 'b', 'c'),
'bar' => array('x', 'y', 'z')
);
$result = array();
foreach ($array['foo'] as $key => $foo) {
$result[] = array('foo' => $foo, 'bar' => $array['bar'][$key]);
}
// result: array(array('foo' => 'a', 'bar' => 'x'), array('foo' => 'b', 'bar' => 'y'), ...)