亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從數據庫生成php數組while循環

從數據庫生成php數組while循環

PHP
瀟瀟雨雨 2021-12-03 19:05:55
我想從我從 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

);


查看完整回答
反對 回復 2021-12-03
  • 1 回答
  • 0 關注
  • 227 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號