[英]How to add an array to an existing two-dimensional array (for use in Highcharts)
I am trying to insert an array into a two-dimensional array. 我正在尝试将数组插入二维数组。 But whatever I try - inserting it as an array, as text, array_push, ... - it won't do what I want.
但是无论我如何尝试-将其作为数组,文本,array_push等插入-都无法满足我的要求。
I have this piece of code which describes the content and look-and-feel of a graph: 我有这段代码描述了图形的内容和外观:
$data_ = array( "chart" => array("renderTo" => "container", "type" => "spline",
"zoomType" => "xy"),
"tooltip" => array("shared" => true, "crosshairs" => true),
"series" => $data);
Now, based on a parameter passed through the JSON call, it could be that the border of the graph shall be displayed (default is "no border"). 现在,基于通过JSON调用传递的参数,可能会显示图形的边框(默认为“无边框”)。
if ($_GET["border"] == true)
{
$border = array("borderWidth" => 1, "borderRadius" => 5, "borderColor" => "#666", "shadow" => true);
}
Now, how do I get the $border into the " chart "-part of $data_ ? 现在,如何将$ border放入$ data_的“ 图表 ”部分?
I tried something like this (by defining the $border before the $data_ ): 我尝试过这样的事情(通过在$ data_之前定义$ border ):
$data_ = array( "chart" => array("renderTo" => "container", "type" => "spline",
"zoomType" => "xy", $border),
"tooltip" => array("shared" => true, "crosshairs" => true),
"series" => $data);
and like this: 像这样:
$data_["chart"][] = $border;
(plus many others). (加上许多其他)。 But this always results - obviously and understandably - in $border being inserted as an array in "chart", and not having the params at the same level, that is:
但这总会导致-显然并且可以理解-将$ border作为数组插入“图表”中,而参数没有处于同一级别,即:
I get this: 我得到这个:
$data_ = array( "chart" => array("renderTo" => "container", "type" => "spline",
"zoomType" => "xy",
array("borderWidth" => 1, "borderRadius" => 5, "borderColor" => "#666", "shadow" => true)),
instead of this: 代替这个:
$data_ = array( "chart" => array("renderTo" => "container", "type" => "spline",
"zoomType" => "xy",
"borderWidth" => 1, "borderRadius" => 5, "borderColor" => "#666", "shadow" => true),
I guess the solution is pretty simple, but unfortunately not known to me. 我猜解决方案很简单,但不幸的是我不知道。 Thanks a lot for any hints!
非常感谢您的任何提示!
I'd try with $data_['chart'] = array_merge($data_['chart'], $border);
我会尝试
$data_['chart'] = array_merge($data_['chart'], $border);
An example: 一个例子:
$a = array("chart" => array(1, 2, 3));
$b = array(4, 5, 6);
$a['chart'] = array_merge($a['chart'], $b);
var_dump($a['chart']);
Displays: 显示:
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.