I have a loop which uses array_push()
to insert new values into my array. Sometimes, a new value which is going to be "pushed in" looks similar to an existing value. Therefore, the array might include "duplicates", which are not exactly similar.
I've tried using in_array()
, but it looks like the values have to be exactly similar to each other.
Does anyone have any suggestions how I could write an if-statement to avoid "duplicates" in my array.
This is a simplified version of my script:
for ($y=0; $y<=1000; $y++) {
$array = array();
array_push($feed,
array(
"name" => $name,
"line" => $line,
"duration" => $duration
)
)
}
I would like to check if $line
is similar to existing ones before I push the array. The lines are collected from another script. By smilar I mean: the 10 first characters are equal substr($line, 0, 10)
Thanks in advance!
You can try this codes. such as
foreach($something as $value){
if(!in_array($value, $liste, true)){
array_push($liste, $value);
}
}
I am sure it take only unique value in your array. Best of luck!