i reinvented the wheel mam because everything i am getting was fine when i have to switch only one blog id. When it comes to switch multiple blog_ids at same time then problem comes with switch_to_blog() function because foreach loop iteration is not working with switch function..now i don’t want to change code for whole site and use other functions. if you have an idea of how to do it right then i will really thankfull to you.
global $wpdb;
$query = "
SELECT blog_id
FROM $wpdb->blogs
WHERE site_id = %d
AND public = '1'
AND archived = '0'
AND mature = '0'
AND spam = '0'
AND deleted = '0'
AND blog_id != '1'
ORDER BY blog_id ASC";
$blogs = $wpdb->get_col( $wpdb->prepare( $query, $wpdb->siteid) );
foreach ($blogs as $blog){
switch_to_blog($blog['blog_id']);
code //
restore_current_blog();
}