skip to Main Content
[0] => Array
    (
        [event_date] => 2023-10-15
        [sale_id] => 11959
        [product_name] => 10x10 Commercial Pop-Up Tent | IMPACT Poly Top
        [product_id] => 14
        [qty_stock] => 3
        [qty_booked] => 10
        [qty_deficit] => -7
        [eventDate] => 2023-10-13
        [pickupDate] => 2023-10-16
    )

[1] => Array
    (
        [event_date] => 2023-10-15
        [sale_id] => 11959
        [product_name] => 10x10 Commercial Pop-Up Tent | IMPACT Poly Top
        [product_id] => 14
        [qty_stock] => 3
        [qty_booked] => 10
        [qty_deficit] => -7
        [eventDate] => 2023-10-15
        [pickupDate] => 2023-10-15
    )

I want olny one array element from here.

 [0] => Array
        (
            [event_date] => 2023-10-15
            [sale_id] => 11959
            [product_name] => 10x10 Commercial Pop-Up Tent | IMPACT Poly Top
            [product_id] => 14
            [qty_stock] => 3
            [qty_booked] => 10
            [qty_deficit] => -7
            [eventDate] => 2023-10-13
            [pickupDate] => 2023-10-16
        )

2

Answers


  1. Possible duplicate of: PHP Removing duplicate objects from array

    Accepted answer is also working on arrays.

    Login or Signup to reply.
  2. An option could be to use a custom filter function like:

        function array_unique_multidimensional(array $array): array {
            
            $sums = [];
            $return_array = [];
            
            foreach($array as $element) {
                $sum = md5(join('', $element));
                if(!in_array($sum, $sums)) {
                    $sums[] = $sum;
                    $return_array[] = $element;
                }
            }
            
            return $return_array;
        }
    

    This of course requires that keys in your array elements always come in the same order and that you want to filter uniquely based on all keys.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search