I am trying to figure out what way of getting to the same result is better, as in faster, less memory usage.
$resp = [];
foreach($data as $val){
$resp[$val] = $val;
}
return array_values($resp);
vs
$resp = [];
foreach($data as $val){
if(!\in_array($val, $resp, false)){
$resp[] = $val;
}
}
return $resp;
I was thinking that the first option would use more memory since it will have values as keys,
but the second option would use more cpu since it will have to check in_array
for an ever growing array.
Any ideas?
The result should be
[
0 => 'no dup data',
1 => 'no dup data 1',
...
]