Given this working code:
$input_array = array(
"192.168.1.100",
"192.168.1.101",
"192.168.1.100",
"192.168.1.102",
"192.168.1.103",
"192.168.1.198",
"192.168.1.101",
"192.168.1.25",
"192.168.1.109",
"192.168.1.109",
"192.168.1.109",
"192.168.1.100",
"192.168.1.58"
);
$final_array = array();
foreach ($input_array as $value) {
//if the value is present more or eq 3 times
if (count(array_keys($input_array, $value)) >= 3) {
//Add it to final array
$final_array[] = $value;
//Echo in the console
echo "IP $value will be banned!" . PHP_EOL;
//Clean up the input array
foreach ($input_array as $k => $v) {
if ($value == $v) {
unset($input_array[$k]);
}
}
}
}
How would you optimize the "Clean up the input array" phase? Is there a way to delete all the items in the input array those matches the if condition?
Thanks everyone