Here is my current code:
if ( by == 'id') {
handlePromises(identifier_websites)
} else if ( by == 'name'){
handlePromises(names_websites)
} else if ( by == 'email' ) {
handlePromises(email_websites)
} else if ( by == 'phone' ) {
handlePromises(phone_websites)
}
Now I want to make it a little bit more modular (functional). I mean, I want to make the whole code above based on an array like this:
$parts = ['id', 'name', 'email', 'phone'];
So if I add one item to that array, then automatically a else if
block should be added to the code based on that item .
Is doing that possible?
Not sure if I get you but here's how you can automate the above slightly.
$parts = [
'id' => identifier_websites,
'name' => names_websites,
'email' => emails_websites,
'phone' => phone_websites
];
foreach ($parts as $cond => $params) {
if (by == $cond) {
handlePromises($params);
break;
}
}