php - Associative Array with Variable Values -


i have been looking on place need i'm not getting anywhere. not sure if because thing want isn't allowed or don't' know how word find solution.

i creating excel export has lot of worksheets there lot of repetitive code made foreach loop. problem array have has variables inside , need code put specific variables spots need it.

 $y1953 =& $workbook->add_worksheet('1953');  $y1958 =& $workbook->add_worksheet('1958');  $y1963 =& $workbook->add_worksheet('1963');  $y1978 =& $workbook->add_worksheet('1978');  $y1988 =& $workbook->add_worksheet('1988');  $y2003 =& $workbook->add_worksheet('2003');         $yearlist = array($y1953 => '1953', $y1958 => '1958', $y1963 => '1963', $y1978 => '1978', $y1988 => '1988', $y2003 => '2003');     foreach ($yearlist $year => $yearnum){    $line = 1; # start on line 2     # write each line        foreach ($bll->rows $row) {         $numberlist = array (''=>'1', '2'=>'2', '3' => '3', '4' => '4');        foreach ($numberlist $name => $num){       if ($row['gyear'.$name] === $yearnum){             $col = 0;                    $year->write_string($line, $col, ''); $col += 1;             $year->write_string($line, $col, $row['name_last'.$name]);$col += 1;             $year->write_string($line, $col, $row['name_first'.$name]); $col += 1;             $year->write_string($line, $col, $row['name_last']); $col +=1;              if($row['session'. $num .'1'] === '1')             {             $year->write_number($line, $col, $row['session'. $num .'1'] );               }$col += 1;             if($row['session'. $num .'2'] === '1')             {             $year->write_number($line, $col, $row['session'. $num .'2'] );              }$col += 1;              if($row['session'. $num .'3'] === '1')             {             $year->write_number($line, $col, $row['session'. $num .'3'] );              }$col += 1;              if($row['session'. $num .'4'] === '1')             {             $year->write_number($line, $col, $row['session'. $num .'4'] );              }$col += 1;              if($row['session'. $num .'5'] === '1')             {             $year->write_number($line, $col,$row['session'. $num .'5'] );              }$col += 1;              if($row['session'. $num .'6'] === '1')             {             $year->write_number($line, $col, $row['session'. $num .'6'] );             }$col += 1;               $year->write_number($line, $col, '1'); $col +=1;             $year->write_string($line, $col, $row['notes']); $col += 1;                  $line += 1;        }       }   } 

$yearlist array having trouble with. need first value "$y1953" $year in foreach loop. right now, nothing shows in excel sheet. there way have code put variable in spot need it? or variables values?

i differently person making excel export wants specific way.

thanks

arrays , objects can not used keys. doing result in warning: illegal offset type.

http://php.net/manual/en/language.types.array.php

try switching keys , values around in array declaration.

$yearlist = array('1953' => $y1953, '1958' => $y1958......etc. 

than change foreach

foreach ($yearlist $yearnum => $year) 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -