As mentioned, you’re doing several things wrong, namely mismatching field names & undefined variables:
function checkbox(){
global $post;
if ( ! is_array( $user_ids = get_post_meta( $post->ID, 'user_ids', true ) ) )
$user_ids = array();
$users = get_users();
foreach ( $users as $user ) {
?>
<input id="user_field_<?php echo $user->ID ?>" type="checkbox" name="user_ids[]" value="<?php echo $user->ID ?>" <?php checked( in_array( $user->ID, $user_ids ) ) ?> />
<label for="user_field_<?php echo $user->ID ?>"><?php echo $user->display_name ?></label><br />
<?php
}
echo '<input type="hidden" name="user_ids[]" value="0" />';
}
/**
* Handler for saving our checkbox states.
*
* @param int $post_id The current post being saved.
*/
function save_detail( $post_id ) {
if ( isset( $_POST['user_ids'] ) ) {
$user_ids = array_map( 'absint', ( array ) $_POST['user_ids'] );
$user_ids = array_filter( $user_ids );
update_post_meta( $post_id, 'user_ids', $user_ids );
}
}
add_action( 'save_post', 'save_detail' );