gpt4 book ai didi

php - 从Mysql数据为Flot创建数组

转载 作者:行者123 更新时间:2023-11-29 07:45:48 26 4
gpt4 key购买 nike

我有一个问题,无法将数组放入数组中。

结果应该是这样的:

$data=array(
array(
'label' => 'Totals',
'color' => '#745fa4',
'data' =>
array(
array('01/01/2015', 125),
array('02/01/2015', 148),
array('03/01/2015', 42),
array('04/01/2015', 115),
array('05/01/2015', 45),
array('06/01/2015', 77),
array('07/01/2015', 59)
)
),
);

我目前有这个,但无法将其转换为正确的格式:

$result = mysqli_query($con,"SELECT * FROM table ORDER BY id DESC LIMIT 28");

$chartdata = array();
while($row = $result->fetch_assoc()) {
$chartdata[] .= array($row["date"]. ", " . $row["total"]);
}

$data=array(
array(
'label' => 'Totals',
'color' => '#745fa4',
'data' => $chartdata
)
);

如果有人能帮助我,那就太好了。

最佳答案

1) .= 这意味着使用字符串连接进行赋值。你应该将数组插入父数组

2) 子数组内部有两个值而不是单个字符串,因此在两个值之间使用 , 而不是字符串连接 ","

$chartdata[] .= array($row["date"]. ", " . $row["total"]);

$chartdata[] = array($row["date"],  $row["total"]);

关于php - 从Mysql数据为Flot创建数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27837965/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com