php - how to insert into array after one iteration of loop? -


I have an array of related products and each has some websites, which I want to store them all in just one array. My problem is that when the loop goes to other related products then it will not store the other and I used the $ web [] and it will show me the right, but shown in a two-dimensional array Because I started it as a sir Mr. and am then I put it in the other array. The reason is that I have $ web = array (); It is that this is part of my code which is included in other code, so I must free up my array so that I used this method.the code and the output is given below:

  & Lt ;? Php echo "------- related ---------- & lt; br & gt;"; Echo 'Productivity:'. $ Productivity "& Lt; br & gt;"; $ _product = Dana :: Millmodel ('catalog / product') - & gt; Load ($ productivity); $ Web = array (); Foreach ($ _product- & gt; getRelatedProducts () $ _product) {echo 'related website id for:'. $ _ PRODUCT- & gt; GetSku () '& lt; Br> & # 39; & # 39; Echo '& lt; Pre & gt; In relation to website id: & lt; Br> & # 39; & # 39; Echo "============="; $ Web + = $ _ product- & gt; GetWebsiteIds (); Echo "============="; Print_r ($ _product-> getWebsiteIds ()); Echo "===== inside the array ===="; Print_r ($ web); Echo "& lt; br & gt; related webcount:". Print_r (count ($ web)). "& Lt; br & gt;"; } Echo & lt; Br> '; Echo "array of all related products:"; Forex currency ($ web = & gt; $ value as web $) {echo "prefix"; Revert $ key "= & gt;" $ Value; } Echo "& lt; br & gt; 
COUNT". Count ($ web); Echo & lt; / Pre & gt; '; Echo "-------------------------"; ? & Gt;

Output:

  ------- related ---------- Productivity: 78110 Related website ID: XXXXXX related Website ID: ========================== Oops ([0] => 1 [1] => 3 [2] = & Gt; 4 [3] => 13 [4] => 14 [5] => 16 [6] => 17 [7] => 18 [8] = & Gt; 19 [9] => 20 [10] => 21 [11] => 23 [12] => 24 [13] => 25 [14] = & gt; ; 26 [15] => 27 [16] => [28] [28] [21] => 35 [22] => 36 [23] => 38 [24] => 40 [25] => 41 [26] => 46 [27 ] = & Gt; 47 [28] => 48 [29] => 50 [30] => 51 [31] => 75) ===== Inside the array === = Array ([0] => 1 [1] => 3 [2] => 4 [3] => 13 [4] => 14 [5] = & gt; 16 [6] => 17 [7] => 18 [8] => 19 [ 9] = & gt; 20 [10] => 21 [11] = & gt; 23 [12] => 24 [13] = & gt; 25 [14] => 26 [15] => [27] [27] 31 [20] = & gt; 34 [21] = & gt; 35 [22] = & gt; 36 [23] = & gt; 38 [24] = & gt; 40 [25] = & gt; 41 [26] = & gt; 46 [27] = & gt; 47 [28] = & gt; 48 [2 9] = & gt; 50 [30] = & gt; 51 [31] = & gt; 75) Related in 32 webcount: 1 related website id for: related yyyyyy website id: ================================================================ 0] = & gt; 0 [1] => 50 [2] => 51) ==== Array inside array (= 0] => 1 [1] = > 3 [2] = & gt; 4 [3] => 13 [4] => 14 [5] => 16 [6] => 17 [7] = & gt; ; 18 [8] => 19 [9] => 20 [10] => 21 [11] => 23 [12] => 24 [13] => 25 [14] = & gt; 26 [15] => 27 [16] => 28 [17] => 29 [18] => 30 [19] => 31 [20] ] => [34] => [35] 46 [27] => 47 [28] => 48 [29] => 50 [30] => 51 [31] => 75) In relation to 32 webcount: 1 array of all related products: 0 = & gt; 1 = 1 & gt; 3 = 2 = 4 = 3 = 13 4 = & gt; 14 = 5 & gt; 16 = 6 = 17 7 = & gt; 18 8 = & gt; 19 9 = & gt; 20 + 10 = & gt; 21 11 = & gt; 23 12 = & gt; 24 13 = & gt; 25 14 = & gt; 26 15 = & gt; 27 16 = & Gt; 28 17 = & gt; 29 = 18 = 30 = 19 = & gt; 31 20 = & gt; 34 = 21 = 35 = 22 & gt; 36 23 = & gt; 38 24 = & gt; 40 = 25 = 41 26 = & gt; 46 27 = & gt; 47 = 28 = & gt; 48 29 = & gt; 50 = 30 = 51 31 = & gt; 75 COUNT32 -------------------------  

As you look for other related products, my There are 3 items but still there is no difference for the array

However your question is for me Not quite clear, but I think you want to list all website IDs in the same one-dimensional array.

In that case you

> $ web = array_merge ($ web, $ _product- & gt; getWebsiteIds ());


Comments