Order array in PHP for one key value (with fields with integer values) [duplicate]

-4

I have a multidimensional array of type

echo "<pre>";
print_r($order_info);
exit();
Array
(
    [0] => Array
        (
            [order_product_id] => 3227
            [seller_id] => 27
        )
    [1] => Array
        (
            [order_product_id] => 3249
            [seller_id] => 1
        )
    [2] => Array
        (
            [order_product_id] => 3040
            [seller_id] => 27
        )
    [3] => Array
        (
            [order_product_id] => 1240
            [seller_id] => 1
        )

I would like to organize it ASCENDENTLY by seller_id

or I'd like it to stay the same:

Array
(
    [1] => Array
        (
            [order_product_id] => 3249
            [seller_id] => 1
        )
    [3] => Array
        (
            [order_product_id] => 1240
            [seller_id] => 1
        )
    [0] => Array
        (
            [order_product_id] => 3227
            [seller_id] => 27
        )
    [2] => Array
        (
            [order_product_id] => 3040
            [seller_id] => 27
        )

That is, I would like to group them by seller_id (which is not another array)

What do I have to do with my array $order_info ?

    
asked by anonymous 20.11.2018 / 16:11

1 answer

0

I think this will solve your problem.

function ordenarPorSellerID($a, $b) { 
    return (($a['seller_id'] != $b['seller_id']) ? (($a['seller_id'] < $b['seller_id']) ? -1 : 1) : 0);
}
    
20.11.2018 / 16:56