我想从我从 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 关注
- 200 浏览
添加回答
举报
0/150
提交
取消