gpt4 book ai didi

PHP 和 JSON : Multidimensional JSON combine format tweaking

转载 作者:行者123 更新时间:2023-11-29 14:20:59 24 4
gpt4 key购买 nike

到目前为止我的 JSON 输出是这样的

[{"dateClose":"2012-07-06","countno":"6","cumulative_sumc":"103"}],[{"dateOpen":"2012-05-29","openNo":"73","cumulative_sum":"73"}]

事实上我希望像下面这样,只是在一个多维数组中

[{"dateClose":"2012-07-06","countno":"6","cumulative_sumc":"103","dateOpen":"2012-05-29","openNo":"73","cumulative_sum":"73"}]

我一直在对project1[]和project[]数组使用array_merge、array_combine,但没有运气。我的示例代码如下。任何帮助将不胜感激。谢谢。

   <?php
require_once('mysql.inc.php');
$dbc =@mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD,DB_NAME);
$x="Set @csum := 0";
$q = "
select dateClose, countno, (@csum := @csum + countno) as cumulative_sumc
from dateclose
order by dateClose";
$rx = mysqli_query($dbc, $x);
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) > 0) {
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
$project[] = $row;
}}
$y="Set @csum := 0";
$z = "
select dateOpen, openNo, (@csum := @csum + openNo) as cumulative_sum
from dateopen
order by dateOpen";
$rx = mysqli_query($dbc, $y);
$r = mysqli_query($dbc, $z);
if (mysqli_num_rows($r) > 0) {
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
array_push($project, $row);
}}


echo json_encode($project);


?>

最佳答案

尝试在脚本中使用 $project[] = $row; 而不是 $project1[] = $row; 来实现 JSON 输出。

关于PHP 和 JSON : Multidimensional JSON combine format tweaking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11762151/

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