It doesn't work the way you wrote it in the question. The function _create_days() is called and it returns a value that replaces the function call. Even if the function returns multiple values in an array, the array as a whole is placed in the outer array you want to build.
The solution is to write the function _create_days() to return an array of values and merge this returned array into the outer array using array_merge() for example:
function _create_days()
{
return array(
'2016-01-01',
'2016-01-02',
);
}
$header = array_merge(
array(
'name',
'surname',
),
_create_days(),
array(
'total',
)
);
Another option is to use a placeholder when you build $header and replace it later with the values returned by _create_days() using the function array_splice():
$header = array(
'name',
'surname',
'@days@', // this is the placeholder
'total',
);
// Replace the placeholder with the values returned by _create_days()
array_splice(
$header,
array_search('@days@', $header),
1,
_create_days()
);
In order to make the code flexible I used the function array_search() to find the position of the placeholder in $headers. This way, if you add or remove elements before '@days@' the code still works without any adjustment.
php-excel, so I have multidimensional array that is like 1200 lines declaration, so it's like not readable now and after splinting it, it will be very hard to read