我在PHP中创建了一个JSON,如下所示
$result=mysqli_query($mysqli,"SELECT * FROM service_provide WHERE personal_id='".$personal_id."'") or die(mysqli_error($mysqli);
$row = mysqli_fetch_assoc($result);
while($row = mysqli_fetch_assoc($result))
{
$data[] = array(
' fname' => $row['fname'],
' email_id' => $row['email_id'],
' phone_number' => $row['phone_number'],
' state' => $row['state'],
' city' => $row['city'],
' main_id' => $row['main_id'],
' sub_id' => $row['sub_id'],
' service_id' => $row['service_id'],
'portfolio1' => $row['portfolio1'],
'portfolio2' => $row['portfolio2'],
'portfolio3' => $row['portfolio3'],
);
}
$json = json_encode($data);
echo $json;
现在我在PHP中有另一个数组,我希望包含在上面的JSON中。该数组如下。
$service_title=array();
$result5=mysqli_query($mysqli,"SELECT * FROM request_submission WHERE req_personal_id='".$req."'") or die(mysqli_error($mysqli);
while($row5 = mysqli_fetch_assoc($result5))
{
$service_title[]=$row5["service_title"];
}
如何将上面的数组插入我上面提到的PHP JSON中?
答案 0 :(得分:2)
你有两个阵列。 1. $data
和2. $service_title
。
所以你可以使用array_merge()
php函数并将新数组转换为json。
$result = array_merge($data, $service_title);
$json = json_encode($result);
echo $json;