How can I write this in a shorter way?
- by oaziz
This code repeats itself. How can I make it shorter? Maybe by using anonymous function or something?
foreach ($value as $wrong) {
if (starts_with($wrong, '%') and ends_with($wrong, '%')) {
$wrong = trim($wrong, '%');
if (contains($address, $wrong)) {
$corrected_address = str_replace($wrong, $key, $address);
break;
}
}
else {
$wrong = trim($wrong, '%');
if (ends_with($address, $wrong)) {
$corrected_address = str_replace($wrong, $key, $address);
break;
}
}
}
Thanks.