0

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.

2
  • please add an example (or more than one) what you need. Do you wish to remove the array's containing only 1 value? or the last ones? Commented Jun 9, 2020 at 10:44
  • remove duplicate values , example [['7'],['32],['7','32']] to [['7],['32']] or [['7','32']] , is that possible ? thanks before Commented Jun 9, 2020 at 10:50

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.