Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- array(10) {
- [0]=>
- object(stdClass)#37 (6) {
- ["id"]=>
- string(5) "31739"
- ["pro_title"]=>
- string(48) "Блуза с декором из пайеток"
- ["price"]=>
- string(9) "154100.00"
- ["parent_id"]=>
- string(5) "31739"
- ["photo_id"]=>
- string(6) "116489"
- ["value"]=>
- string(7) "Rodarte"
- }
- [1]=>
- object(stdClass)#38 (6) {
- ["id"]=>
- string(5) "31739"
- ["pro_title"]=>
- string(48) "Блуза с декором из пайеток"
- ["price"]=>
- string(9) "154100.00"
- ["parent_id"]=>
- string(5) "31739"
- ["photo_id"]=>
- string(6) "116489"
- ["value"]=>
- string(7) "Rodarte"
- }
- [2]=>
- object(stdClass)#39 (6) {
- ["id"]=>
- string(5) "31739"
- ["pro_title"]=>
- string(48) "Блуза с декором из пайеток"
- ["price"]=>
- string(9) "154100.00"
- ["parent_id"]=>
- string(5) "31739"
- ["photo_id"]=>
- string(6) "116489"
- ["value"]=>
- string(7) "Rodarte"
- }
- [3]=>
- object(stdClass)#40 (6) {
- ["id"]=>
- string(5) "31762"
- ["pro_title"]=>
- string(30) "Свитер из шерсти"
- ["price"]=>
- string(8) "39370.00"
- ["parent_id"]=>
- string(5) "31762"
- ["photo_id"]=>
- string(6) "116609"
- ["value"]=>
- string(5) "MONSE"
- }
- [4]=>
- object(stdClass)#41 (6) {
- ["id"]=>
- string(5) "31762"
- ["pro_title"]=>
- string(30) "Свитер из шерсти"
- ["price"]=>
- string(8) "39370.00"
- ["parent_id"]=>
- string(5) "31762"
- ["photo_id"]=>
- string(6) "116609"
- ["value"]=>
- string(5) "MONSE"
- }
- [5]=>
- object(stdClass)#42 (6) {
- ["id"]=>
- string(5) "31762"
- ["pro_title"]=>
- string(30) "Свитер из шерсти"
- ["price"]=>
- string(8) "39370.00"
- ["parent_id"]=>
- string(5) "31762"
- ["photo_id"]=>
- string(6) "116609"
- ["value"]=>
- string(5) "MONSE"
- }
- [6]=>
- object(stdClass)#43 (6) {
- ["id"]=>
- string(5) "31762"
- ["pro_title"]=>
- string(30) "Свитер из шерсти"
- ["price"]=>
- string(8) "39370.00"
- ["parent_id"]=>
- string(5) "31762"
- ["photo_id"]=>
- string(6) "116609"
- ["value"]=>
- string(5) "MONSE"
- }
- [7]=>
- object(stdClass)#44 (6) {
- ["id"]=>
- string(5) "31765"
- ["pro_title"]=>
- string(25) "Серьги Gold Baroque"
- ["price"]=>
- string(8) "50710.00"
- ["parent_id"]=>
- string(5) "31765"
- ["photo_id"]=>
- string(6) "116492"
- ["value"]=>
- string(7) "Rodarte"
- }
- [8]=>
- object(stdClass)#45 (6) {
- ["id"]=>
- string(5) "31768"
- ["pro_title"]=>
- string(40) "Топ из вискозы и шелка"
- ["price"]=>
- string(8) "90970.00"
- ["parent_id"]=>
- string(5) "31768"
- ["photo_id"]=>
- string(6) "116490"
- ["value"]=>
- string(7) "Rodarte"
- }
- [9]=>
- object(stdClass)#46 (6) {
- ["id"]=>
- string(5) "31768"
- ["pro_title"]=>
- string(40) "Топ из вискозы и шелка"
- ["price"]=>
- string(8) "90970.00"
- ["parent_id"]=>
- string(5) "31768"
- ["photo_id"]=>
- string(6) "116490"
- ["value"]=>
- string(7) "Rodarte"
- }
- }
- $result = [];
- foreach($data as $o) {
- $result[$o->parent_id] = $o;
- }
- //$result = array_values($result);
- print_r($result);
- $data = [......];
- usort($data, function($a, $b) {
- if ($a->parent_id < $b->parent_id)
- return -1;
- else if ($a->parent_id == $b->parent_id)
- return 0;
- else
- return 1;
- });
- $new_data = array_filter(
- $data,
- function($val, $key) {
- return ($key == 0) || ($data[$key - 1]->partent_id != $val->parent_id);
- },
- ARRAY_FILTER_USE_BOTH
- );
- $data = [..........];
- $counts = [];
- foreach ($data as $val) {
- if (!isset($counts[$val->parent_id])
- $counts[$val->parent_id] = 0;
- else
- $counts[$val->parent_id]++;
- };
- $new_data = array_filter(
- $data,
- function($val, $key) {
- if ($counts[$val->parent_id] === 0) {
- return true;
- $counts[$val->parent_id]--;
- return false;
- },
- ARRAY_FILTER_USE_BOTH
- );
Add Comment
Please, Sign In to add comment