I have nested loop while and I'd like to create multidimensional array with some datas from these loops Output should be look like:
'productId'=>1 'productImg'=>some_url 'productContent'=> subarray( 'question1'=>value1 'answer1'=>value1, 'question2'=value2, 'question2'=>value2 )
My code with nested while loops
if (have_rows('dodaj_pytania_do_produktu')): while (have_rows('dodaj_pytania_do_produktu')) : the_row(); $counter = 1; $productID = get_sub_field('nazwa_produktu_faq'); $productImage = get_sub_field('dodaj_zdjecie'); $productsData[] = array( 'productId' => $productID, 'productImg' => $productImage, ); $product = wc_get_product($productID); $productName = $product->get_title(); // Loop over sub repeater rows. if (have_rows('dodaj_pytanie_i_odpowiedz')): while (have_rows('dodaj_pytanie_i_odpowiedz')) : the_row(); $question = get_sub_field('dodaj_pytanie'); $answer = strip_tags(get_sub_field('dodaj_odpowiedz')); $productsData[] = array( 'productDesc'=> array( 'question' => $question, 'answer' => $answer ) ); endwhile; endif; endwhile; else : echo "brak faq"; endif; ?>
Now my output create wrong subarray not creating a subarray