Guest User

Untitled

a guest
Nov 22nd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. array(10) {
  2. [0]=>
  3. object(stdClass)#37 (6) {
  4. ["id"]=>
  5. string(5) "31739"
  6. ["pro_title"]=>
  7. string(48) "Блуза с декором из пайеток"
  8. ["price"]=>
  9. string(9) "154100.00"
  10. ["parent_id"]=>
  11. string(5) "31739"
  12. ["photo_id"]=>
  13. string(6) "116489"
  14. ["value"]=>
  15. string(7) "Rodarte"
  16. }
  17. [1]=>
  18. object(stdClass)#38 (6) {
  19. ["id"]=>
  20. string(5) "31739"
  21. ["pro_title"]=>
  22. string(48) "Блуза с декором из пайеток"
  23. ["price"]=>
  24. string(9) "154100.00"
  25. ["parent_id"]=>
  26. string(5) "31739"
  27. ["photo_id"]=>
  28. string(6) "116489"
  29. ["value"]=>
  30. string(7) "Rodarte"
  31. }
  32. [2]=>
  33. object(stdClass)#39 (6) {
  34. ["id"]=>
  35. string(5) "31739"
  36. ["pro_title"]=>
  37. string(48) "Блуза с декором из пайеток"
  38. ["price"]=>
  39. string(9) "154100.00"
  40. ["parent_id"]=>
  41. string(5) "31739"
  42. ["photo_id"]=>
  43. string(6) "116489"
  44. ["value"]=>
  45. string(7) "Rodarte"
  46. }
  47. [3]=>
  48. object(stdClass)#40 (6) {
  49. ["id"]=>
  50. string(5) "31762"
  51. ["pro_title"]=>
  52. string(30) "Свитер из шерсти"
  53. ["price"]=>
  54. string(8) "39370.00"
  55. ["parent_id"]=>
  56. string(5) "31762"
  57. ["photo_id"]=>
  58. string(6) "116609"
  59. ["value"]=>
  60. string(5) "MONSE"
  61. }
  62. [4]=>
  63. object(stdClass)#41 (6) {
  64. ["id"]=>
  65. string(5) "31762"
  66. ["pro_title"]=>
  67. string(30) "Свитер из шерсти"
  68. ["price"]=>
  69. string(8) "39370.00"
  70. ["parent_id"]=>
  71. string(5) "31762"
  72. ["photo_id"]=>
  73. string(6) "116609"
  74. ["value"]=>
  75. string(5) "MONSE"
  76. }
  77. [5]=>
  78. object(stdClass)#42 (6) {
  79. ["id"]=>
  80. string(5) "31762"
  81. ["pro_title"]=>
  82. string(30) "Свитер из шерсти"
  83. ["price"]=>
  84. string(8) "39370.00"
  85. ["parent_id"]=>
  86. string(5) "31762"
  87. ["photo_id"]=>
  88. string(6) "116609"
  89. ["value"]=>
  90. string(5) "MONSE"
  91. }
  92. [6]=>
  93. object(stdClass)#43 (6) {
  94. ["id"]=>
  95. string(5) "31762"
  96. ["pro_title"]=>
  97. string(30) "Свитер из шерсти"
  98. ["price"]=>
  99. string(8) "39370.00"
  100. ["parent_id"]=>
  101. string(5) "31762"
  102. ["photo_id"]=>
  103. string(6) "116609"
  104. ["value"]=>
  105. string(5) "MONSE"
  106. }
  107. [7]=>
  108. object(stdClass)#44 (6) {
  109. ["id"]=>
  110. string(5) "31765"
  111. ["pro_title"]=>
  112. string(25) "Серьги Gold Baroque"
  113. ["price"]=>
  114. string(8) "50710.00"
  115. ["parent_id"]=>
  116. string(5) "31765"
  117. ["photo_id"]=>
  118. string(6) "116492"
  119. ["value"]=>
  120. string(7) "Rodarte"
  121. }
  122. [8]=>
  123. object(stdClass)#45 (6) {
  124. ["id"]=>
  125. string(5) "31768"
  126. ["pro_title"]=>
  127. string(40) "Топ из вискозы и шелка"
  128. ["price"]=>
  129. string(8) "90970.00"
  130. ["parent_id"]=>
  131. string(5) "31768"
  132. ["photo_id"]=>
  133. string(6) "116490"
  134. ["value"]=>
  135. string(7) "Rodarte"
  136. }
  137. [9]=>
  138. object(stdClass)#46 (6) {
  139. ["id"]=>
  140. string(5) "31768"
  141. ["pro_title"]=>
  142. string(40) "Топ из вискозы и шелка"
  143. ["price"]=>
  144. string(8) "90970.00"
  145. ["parent_id"]=>
  146. string(5) "31768"
  147. ["photo_id"]=>
  148. string(6) "116490"
  149. ["value"]=>
  150. string(7) "Rodarte"
  151. }
  152. }
  153.  
  154. $result = [];
  155. foreach($data as $o) {
  156. $result[$o->parent_id] = $o;
  157. }
  158.  
  159. //$result = array_values($result);
  160. print_r($result);
  161.  
  162. $data = [......];
  163. usort($data, function($a, $b) {
  164. if ($a->parent_id < $b->parent_id)
  165. return -1;
  166. else if ($a->parent_id == $b->parent_id)
  167. return 0;
  168. else
  169. return 1;
  170. });
  171. $new_data = array_filter(
  172. $data,
  173. function($val, $key) {
  174. return ($key == 0) || ($data[$key - 1]->partent_id != $val->parent_id);
  175. },
  176. ARRAY_FILTER_USE_BOTH
  177. );
  178.  
  179. $data = [..........];
  180. $counts = [];
  181. foreach ($data as $val) {
  182. if (!isset($counts[$val->parent_id])
  183. $counts[$val->parent_id] = 0;
  184. else
  185. $counts[$val->parent_id]++;
  186. };
  187. $new_data = array_filter(
  188. $data,
  189. function($val, $key) {
  190. if ($counts[$val->parent_id] === 0) {
  191. return true;
  192. $counts[$val->parent_id]--;
  193. return false;
  194. },
  195. ARRAY_FILTER_USE_BOTH
  196. );
Add Comment
Please, Sign In to add comment