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 来绘制一个 groupbar。新的 Bra 对象是这样创建的

$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;
    }

共有三个条形图plot2013、plot2014、plot2015。这三个都是数组。我想将这些数组传递给下面给出的 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);