如何将数组添加到现有的二维数组(用于 Highcharts)
How to add an array to an existing two-dimensional array (for use in Highcharts)
我正在尝试将数组插入到二维数组中。但无论我尝试什么 - 将它作为数组插入,作为文本,array_push,... - 它不会做我想要的。
我有这段代码描述了图形的内容和外观:
$data_ = array( "chart" => array("renderTo" => "container", "type" => "spline",
"zoomType" => "xy"),
"tooltip" => array("shared" => true, "crosshairs" => true),
"series" => $data);
现在,根据通过 JSON 调用传递的参数,可能会显示图表的边框(默认为 "no border")。
if ($_GET["border"] == true)
{
$border = array("borderWidth" => 1, "borderRadius" => 5, "borderColor" => "#666", "shadow" => true);
}
现在,如何将 $border 放入“chart”- $data_[ 的一部分=41=]?
我试过这样的事情(通过在 $data_ 之前定义 $border):
$data_ = array( "chart" => array("renderTo" => "container", "type" => "spline",
"zoomType" => "xy", $border),
"tooltip" => array("shared" => true, "crosshairs" => true),
"series" => $data);
像这样:
$data_["chart"][] = $border;
(加上许多其他)。
但这总是导致 - 显然并且可以理解 - $border 被作为数组插入 "chart",并且没有在同一级别的参数,即:
我明白了:
$data_ = array( "chart" => array("renderTo" => "container", "type" => "spline",
"zoomType" => "xy",
array("borderWidth" => 1, "borderRadius" => 5, "borderColor" => "#666", "shadow" => true)),
而不是这个:
$data_ = array( "chart" => array("renderTo" => "container", "type" => "spline",
"zoomType" => "xy",
"borderWidth" => 1, "borderRadius" => 5, "borderColor" => "#666", "shadow" => true),
我想解决方案很简单,但不幸的是我不知道。非常感谢任何提示!
我会尝试 $data_['chart'] = array_merge($data_['chart'], $border);
一个例子:
$a = array("chart" => array(1, 2, 3));
$b = array(4, 5, 6);
$a['chart'] = array_merge($a['chart'], $b);
var_dump($a['chart']);
显示:
array(6) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
[5]=>
int(6)
}
我正在尝试将数组插入到二维数组中。但无论我尝试什么 - 将它作为数组插入,作为文本,array_push,... - 它不会做我想要的。
我有这段代码描述了图形的内容和外观:
$data_ = array( "chart" => array("renderTo" => "container", "type" => "spline",
"zoomType" => "xy"),
"tooltip" => array("shared" => true, "crosshairs" => true),
"series" => $data);
现在,根据通过 JSON 调用传递的参数,可能会显示图表的边框(默认为 "no border")。
if ($_GET["border"] == true)
{
$border = array("borderWidth" => 1, "borderRadius" => 5, "borderColor" => "#666", "shadow" => true);
}
现在,如何将 $border 放入“chart”- $data_[ 的一部分=41=]?
我试过这样的事情(通过在 $data_ 之前定义 $border):
$data_ = array( "chart" => array("renderTo" => "container", "type" => "spline",
"zoomType" => "xy", $border),
"tooltip" => array("shared" => true, "crosshairs" => true),
"series" => $data);
像这样:
$data_["chart"][] = $border;
(加上许多其他)。 但这总是导致 - 显然并且可以理解 - $border 被作为数组插入 "chart",并且没有在同一级别的参数,即:
我明白了:
$data_ = array( "chart" => array("renderTo" => "container", "type" => "spline",
"zoomType" => "xy",
array("borderWidth" => 1, "borderRadius" => 5, "borderColor" => "#666", "shadow" => true)),
而不是这个:
$data_ = array( "chart" => array("renderTo" => "container", "type" => "spline",
"zoomType" => "xy",
"borderWidth" => 1, "borderRadius" => 5, "borderColor" => "#666", "shadow" => true),
我想解决方案很简单,但不幸的是我不知道。非常感谢任何提示!
我会尝试 $data_['chart'] = array_merge($data_['chart'], $border);
一个例子:
$a = array("chart" => array(1, 2, 3));
$b = array(4, 5, 6);
$a['chart'] = array_merge($a['chart'], $b);
var_dump($a['chart']);
显示:
array(6) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
[5]=>
int(6)
}