【发布时间】:2014-04-25 05:34:35
【问题描述】:
我在$result1 = implode(' ',$result1)时遇到错误
我使用 2 个查询并希望将结果合并为一个,这是我的查询:
if($stmt->execute()){
$user = $stmt->get_result();
while ($obj = $user->fetch_object()) {
$result1[] = $obj;
}
}
if($stmt->execute()){
$user = $stmt->get_result();
while ($obj = $user->fetch_object()) {
$result2[] = $obj;
}
}
- 在此处将 $result1 和 result2 转换为字符串
-
我需要 $result1 和 result2 像
'[{ "uId":"1", "firstName":"James", "lastName":"Bond" }]'
以便它可以在下面的代码中运行。
$arr1 = json_decode($result1,true);
$arr2 = json_decode($result2,true);
$arr1[0]['task'] = $arr2;
$finalJSON = json_encode($arr1);
echo $finalJSON;
【问题讨论】:
-
任何时候你提到你有一个错误,请包括你收到的实际错误。那是什么?
-
json_encode ...
-
为什么需要将你的对象编码成 json 并将其解码回数组?