Reynaldo
Reynaldo

Reputation: 57

how to remove duplicate data at array?

can somebody help me ?

i have variable containing an array from another function :

//variable from apriori function
$mightAlsoLike = $this->apriori();
dd($mightAlsoLike);

and the variable return like this:

[
  [
    "7"
  ],
  [
    "32"
  ],
  [
  "7",
  "32"
  ]
]

my probelm is how can u to remove duplicate id at array variable ? im newb ,very grateful if anyone helps.

sorry for my broken english, thanks.

Upvotes: 0

Views: 40

Answers (1)

Ivo P
Ivo P

Reputation: 1712

You could do it like this:

<?php

$data = [[7], [32], [1,2], [2,32]];

foreach($data as $sub) {
    foreach($sub as $val[]);
}
$val = array_unique($val);
var_dump($val);

Upvotes: 1

Related Questions