The php two-dimensional array is divided into a new array based on the addition of the price value and the splits greater than 20.

problem description

php two-dimensional array is divided into a new array based on the addition of price values and those greater than 20

related codes

/ / Please paste the code text below (do not replace the code with pictures)
Array
(

)
[0] => Array
    (
        [inventory_type] => 1
        [order_goods] => Array
            (
                [0] => Array
                    (
                        [id] => 162646434
                        [price] => 7.65
                        [goods_id] => 274774
                    )

                [1] => Array
                    (
                        [id] => 162646435
                        [price] => 12.46
                        [goods_id] => 445018
                    )

                [2] => Array
                    (
                        [id] => 162646436
                        [price] => 17.00
                        [goods_id] => 461913
                    )

                [3] => Array
                    (
                        [id] => 162646437
                        [price] => 10.68
                        [goods_id] => 408752
                    )

            )

    )

)

what result do you expect? What is the error message actually seen?

Array
(

)
[0] => Array
    (
        [inventory_type] => 1
        [order_goods] => Array
            (
                [0] => Array
                    (
                        [id] => 162646434
                        [price] => 7.65
                        [goods_id] => 274774
                    )

                [1] => Array
                    (
                        [id] => 162646435
                        [price] => 12.46
                        [goods_id] => 445018
                    )
            )

    )
[1] => Array
    (
        [inventory_type] => 1
        [order_goods] => Array
            (
             
                [0] => Array
                    (
                        [id] => 162646436
                        [price] => 17.00
                        [goods_id] => 461913
                    )

            )

    )
[2] => Array
    (
        [inventory_type] => 1
        [order_goods] => Array
            (
             
                [0] => Array
                    (
                        [id] => 162646437
                        [price] => 10.68
                        [goods_id] => 408752
                    )

            )

    )    

)


I have already written it! Thank you for your support!

public function getData ($list,$inventory_type) {

    $slice = array();
    $newList = array();
    while (!empty($list)) {
        $first = array_shift($list);
        array_push($slice, $first);
        if (array_sum(array_column($slice,'avg_price')) > 650) {
            $last = array_pop($slice);
            array_unshift($list, $last);
            $newList['inventory_type'] = $inventory_type;
            $newList['order_goods'][] = $slice;
            $slice = array();
        }
        if (empty($list) && !empty($slice)) {
            $newList['inventory_type'] = $inventory_type;
            $newList['order_goods'][] = $slice;
            $slice = array();
        }
    }
    return $newList;
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a6a5-2ba64.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a6a5-2ba64.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?