请帮助你,
我试图使用函数来更改PHP变量的名称。我试图将$ name更改为$ graph1,$ graph2 ... $ graph31。这是我制作的代码:
<?php
function bar($name, $label, $value) {
return
$name = new BAR_GRAPH("pBar");
$name->values = $value;
$name->labels = $label;
$name->labelColor = "white";
$name->labelBGColor = "#282828";
$name->barBorder = "0px";
$name->barColors = "white";
$name->barBGColor = "#282828";
$name->showValues = 0;
$name->percValuesColor = "white";
$name->barColors = "white";
echo $name->create();
}
bar("$graph1","ornamen","$totkakiOrnamen;7");
?>
不幸的是,代码不起作用,它说:
注意:未定义的变量:C:\ xampp \ htdocs \ app \ process.php中的图形 在第56行
我不知道出了什么问题。如何将$ name更改为$ graph1,$ graph2 ... $ graph31?
PS:返回代码看起来很奇怪,因为我使用gerd-tentler的脚本来生成水平条。 http://www.gerd-tentler.de/tools/phpgraphs/?page=introduction
答案 0 :(得分:1)
这可能是也可能不是你要问的但也许...... ??
<?php
function bar($name, $label, $value) {
$$name = new BAR_GRAPH("pBar");
$$name->values = $value;
$$name->labels = $label;
$$name->labelColor = "white";
$$name->labelBGColor = "#282828";
$$name->barBorder = "0px";
$$name->barColors = "white";
$$name->barBGColor = "#282828";
$$name->showValues = 0;
$$name->percValuesColor = "white";
$$name->barColors = "white";
$$name->create();
return $$name;
}
$graph1 = bar('graph1',"ornamen","$totkakiOrnamen;7"); ?>
如果没有,唯一的另一个猜测是你试图做一个变量变量: