Just contact PHP, do not know whether you can first create an empty array with a key name, later use in the assignment. Because the number of key names in this array is variable, the array cannot be defined directly.
My idea is as follows:
... $strkeys = "' tagname ' =>, ' Descr ' =>, ' unit ' =>,"; for ($w = 1; $w <= $days; $w + +) { $strkeys = $strkeys. "". $w. " Day ' =>, ';} $strkeys = $strkeys. "' Total ' = = '; $excelres []= Array ($strkeys);//print_r ($excelres);
But the use of Print_r ($excelres), after getting the result and think differently, as follows:
Array ([0] = = Array ([0] = ' tagname ' =>, ' Descr ' =>, ' unit ' =>, ' 1st ' =>, ' 2nd ' =>, ' 3rd ' =>, ' 4th ' =>, ' 5th ' =>, ' 6th ' =>, ' 7th ' =>, ' 8th ' =>, ' 9th ' =>, ' 10th ' =>, ' 11th ' =>, ' 12th ' =>, ' 13th ' =>, ' 14th ' =>, ' 15th ' = , ' 16th ' =>, ' 17th ' =>, ' 18th ' =>, ' 19th ' =>, ' 20th ' =>, ' 21st ' =>, ' 22nd ' =>, ' 23rd ' =>, ' 24th ' =>, ' 25th ' = , ' 26th ' =>, ' 27th ' =>, ' 28th ' =>, ' 29th ' =>, ' 30th ' =>, ' total ' and ' = ' [1] = = Array ([0] = ' tagname ' => ' Descr ' =>, ' unit ' =>, ' 1st ' =>, ' 2nd ' =>, ' 3rd ' =>, ' 4th ' =>, ' 5th ' =>, ' 6th ' =>, ' 7th ' =>, ' 8th ' =>, ' 9th ' = , ' 10th ' =>, ' 11th ' =>, ' 12th ' =>, ' 13th ' =>, ' 14th ' =>, ' 15th ' =>, ' 16th ' =>, ' 17th ' =>, ' 18th ' =>, ' 19th ' = , ' 20th ' =>, ' 21st ' =>, ' 22nd ' =>, ' 23rd ' =>, ' 24th ' =>, ' 25th ' =>, ' 26th ' =>, ' 27th ' =>, ' 28th ' =>, ' 29th ' = (30th ' =>, ' total ' =))
Reply to discussion (solution)
First you create an array that is not in the right format.
$strkeys = [' tagname ' = ' = ', ' descr ' + ', ' unit ' = ']; $days =30;for ($w = 1; $w <= $days; $w + +) { $ strkeys[$w. ' Day ']= ';} $strkeys [' Total ']= ';p rint_r ($strkeys);
[] format is an array shorthand format for PHP 5.4 and later
$strkeys = Array (' tagname ' = ' = ', ' descr ' = ' = ', ' unit ' = ') '; $days = 31;for ($w = 1; $w <= $days; $w + +) {$strkeys [$ W. ' Day '] = ';} $strkeys [' total '] = '; $excelres []= $strkeys;p Rint_r ($excelres);
Array
(
[0] = = Array
(
[TagName] =
[DESCR] =
[Unit] =
[1st] = =
[2nd] = =
[3rd] = =
[4th] = =
[5th] = =
[6th] = =
[7th] = =
[8th] = =
[9th] = =
[10th] = =
[11th] = =
[12th] = =
[13th] = =
[14th] = =
[15th] = =
[16th] = =
[17th] = =
[18th] = =
[19th] = =
[20th] = =
[21st] = =
[22nd] = =
[23rd] = =
[24th] = =
[25th] = =
[26th] = =
[27th] = =
[28th] = =
[29th] = =
[30th] = =
[31st] = =
[Total] =
)
)