我想從我從 while 循環中獲取的數據庫數據生成完全相同的數組,該數組將傳遞給其他一些函數,并且它不接受其他任何內容。當我手動傳遞此數據時,它可以工作,因此它應該完全相同。$putArray7 =array( // "title" => "Test Product " , // "body_html" => "test description" , "images" => array ( array( "id" => "6800163209265", "attachment" => "$attachment_base64", ), array( "id" => "6800163438641", "attachment" => "$attachment_base64", ), array( "id" => "6800164880433", "attachment" => "$attachment_base64", ), ) );我試過的: $response99 = array(); $response_final = array();// data from mysql starts here while($row = mysqli_fetch_assoc($res)) { $response99[] = ['id'=>$id_img_id .',', 'attachment'=>$attachment_base64]; }現在嘗試在此處重新創建整個數組:// did not work $response_final[] = ['title'=>"Test Product 53","body_html" => "test description" , 'images'=>$response99];試過這個: $response_final[] = ['title'=>"Test Product 53","body_html" => "test description" , 'images'=>[$response99]];這個也不起作用:嘗試了其他幾種方法。任何幫助都會很棒。想要生成完全一樣的$putArray7.
1 回答

慕哥6287543
TA貢獻1831條經驗 獲得超10個贊
像這樣做:
$response99 = array();
$response_final = array();
while($row = mysqli_fetch_assoc($res)){
$a = array();
$a['id'] = $row['id'];
$a['attachment'] = $row['attachment'];
$response99[] = $a;
}
$response_final = array(
'title' => "Test Product 53",
'body_html' => "test description" ,
'images' => $response99
);
- 1 回答
- 0 關注
- 227 瀏覽
添加回答
舉報
0/150
提交
取消