[英]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调用传递的参数,可能会显示图形的边框(默认为“无边框”)。
if ($_GET["border"] == true)
{
$border = array("borderWidth" => 1, "borderRadius" => 5, "borderColor" => "#666", "shadow" => true);
}
现在,如何将$ border放入$ data_的“ 图表 ”部分?
我尝试过这样的事情(通过在$ 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作为数组插入“图表”中,而参数没有处于同一级别,即:
我得到这个:
$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)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.