I use the following code to get through each of values
foreach (array('facebook', 'twitter', 'vkontakte', 'mailru', 'odnoklassniki') as $service) {
// Code goes here
}
But I feel there should be more beautiful solution than this one.
You could assign the array to a variable for readability and reuse.
$services = array('facebook', 'twitter', 'vkontakte', 'mailru', 'odnoklassniki');
foreach ( $services as $service) {
// Code goes here
}
Depending on the situation, you could also use array_walk
array_walk($services, 'yourFunction');
function yourFunction(&$value, $key) {
//Code goes here
}
array_mapthat can be useful, but there's nothing wrong with what you've got.