How to get all logged in user id in buddypress [closed]

This $bp->loggedin_user->id will only give you a single id, of the current logged in user.
btw – it also requires use of the $bp global.
You don’t need to use that global. Use bp_loggedin_user_id() instead.

BuddyPress does not track logged in users. It does not use sessions.
It does use timestamps in the database to indicate recent activity.
So you could use custom sql to return user ids.
For example:

function shahid_get_recent_active() {
    global $wpdb;

    $time = time() - (60 * 10); // current time minus 10 minutes
    $cutoff = date('Y-m-d h:i:s', $time);

    $user_ids = $wpdb->get_col( "SELECT user_id FROM {$wpdb->prefix}bp_activity WHERE type="last_activity" AND date_recorded > '$cutoff' " ); 
    var_dump( $user_ids );

}
add_action( 'bp_ready', 'shahid_get_recent_active' );

$user_ids will be an array.