PHP 将在 for 循环中创建的数组传递给 jpgraph 函数


PHP passing array created in for loop to jpgraph function

我按以下方式创建了 3 个数组:

$start=2013 ;
$end=2015;
$no_of_bars=$to-$from+1;
$xdata=array();
for($year=$start;$year<=$end;$year++){
     ${"y".$year}=array();
    $i=0;
    $query=mysql_query("SELECT tld_master.location,tld_dose.year, AVG(tld_dose.dose)*4 as avgdose from tld_master left join tld_dose on tld_master.tldno=tld_dose.tldno where tld_master.site='F' and tld_dose.year=$year GROUP BY tld_dose.year, tld_dose.tldno");
    while($result=mysql_fetch_array($query)){
$xdata[$i]=$result['location'];
 ${"y".$year}[$i]=$result['avgdose'];

$i++;
}
    }

它创建三个数组 y2013、y2014、y2015。

我必须将此数组传递给 jpgrpah 以绘制组栏。以这种方式创建新的文胸对象

$j=0;
for($year=$start;$year<=$end;$year++, $j++){
    ${"plot".$year}=new BarPlot(${"y".$year});
    ${"plot".$year}->SetFillColor($color_array[$j]);
if($year!=$end){$sep=",";}else{$sep="";}
    $plots.="$"."plot".$year.$sep;
    }

有三个条形图图2013,图2014,图2015。这三个都是数组。我想将这些数组传递给下面给出的jpgraph函数:

$gbplot = new GroupBarPlot($plots);

但这行不通。但是如果我将其更改为下面给出的那个,它可以工作

$gbplot = new GroupBarPlot(array($plot2013,$plot2014, $plot2015));

我认为在第二个数组中作为参数传递,而在第一个数组中,数组名称作为字符串传递。如何将在 for 循环中创建的数组传递给 jpgraph 函数?

未测试,但请尝试以下代码。

$j=0;
for($year=$start;$year<=$end;$year++, $j++){
  ${"plot".$year}=new BarPlot(${"y".$year});
  ${"plot".$year}->SetFillColor($color_array[$j]);

  $plots[] = ${"plot".$year};
}
$gbplot = new GroupBarPlot($plots);