1

I want to generate exactly same array from database data which I am getting from while loop which will be passed to some other function and it does not accept anything else.

When i pass this data manually it works so it should be exactly same.

$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",
        ),

 )

   );

What i tried:

  $response99 = array();
  $response_final = array();
// data from mysql starts here 

while($row = mysqli_fetch_assoc($res))

 {
      $response99[] = ['id'=>$id_img_id .',', 
  'attachment'=>$attachment_base64];

   }

Now tried to recreate whole array here:

// did not work 

     $response_final[] = ['title'=>"Test Product 53","body_html" => "test description" , 'images'=>$response99];

Tried this:

    $response_final[] = ['title'=>"Test Product 53","body_html" => "test description" , 'images'=>[$response99]];

This one also did not work:

Tried several other ways. Any help will be great.

Want to generate exactly like $putArray7.

1 Answer 1

0

Do it like this:

$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
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.