我有以下列方式创建的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以绘制组合栏。以这种方式创建新的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;
}
有三个条形图,情节2013,情节2014,情节2015。所有这三个都是数组。我想将这些数组传递给jpgraph函数,如下所示:
$gbplot = new GroupBarPlot($plots);
但这不起作用。但是,如果我将其更改为下面给出的那个,则可以正常工作
$gbplot = new GroupBarPlot(array($plot2013,$plot2014, $plot2015));
我认为在第二个数组中作为参数传递,而在第一个数组中,只是数组名称作为字符串传递。如何将for循环中创建的数组传递给jpgraph函数?
答案 0 :(得分:0)
未经测试,但请尝试下面的代码。
$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);