Loop array of values
I use the following code to get through each of values
foreach (array('facebook', 'twitter', 'vkontakte', 'mailru', 'odnoklassniki')开发者_StackOverflow中文版 as $service) {
// Code goes here
}
But I feel there should be more beautiful solution than this one.
Imo that's the most beatiful solution
If you need further information about loops you can go here
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
}
what you have here fine as far as loops go is the right way to loop , but that does mean that you need a loop just depends on what //codes goes here is
精彩评论