Can I count the number of users matching a value in a multiple value key?

I’m trying to find the number of users having a certain value in a custom field. The problem is that this custom field allow multiple values.
This code works well when the meta_key allows only one value, but how can I get it work with multiple values?

$args = array('meta_key' => 'fruits_user_like', 'meta_value' =>'apple');
$users = get_users($args);
$number_of_users = count($users);

Solutions Collecting From Web of "Can I count the number of users matching a value in a multiple value key?"

If you are working with serialized data as your meta_value, that sucks, as Pieter suggested, it’s best not to.

However if there is no way around the serialization problem then I wonder if a meta_query using a compare value of LIKE might help…

Example:

//psuedo serialized data... (e.g. value of meta_key = fruits_user_like)
//a:4:{i:0;s:5:"apple";i:1;s:6:"orange";i:2;s:6:"banana";i:3;s:31:"serialized_data_sucks_sometimes";}

$users = get_users(   
    array(   
        'meta_query' => array(  
            array(  
                'key'   => 'fruits_user_like',
                'value' => array(
                    'apple', 
                    'orange', 
                    'banana', 
                    'serialized_data_sucks_sometimes'
                ),
                'compare' => 'LIKE'
            )
        )    
    )    
);

…I wonder.

The above won’t work with a compare value of LIKE, we need to use REGEXP and pass a regular expression as the value.

Try the following:

$args = array(   
    'meta_query' => array(
        array(    
            'key'   => 'fruits_user_like',
            'value' => '(apple|orange|banana)',
            'compare' => 'REGEXP'
        )
    ),
    'count_total' => true
);

$users = new WP_User_Query($args);

print_r( $users->get_total() );

Switch to using to WP_User_Query, it’s more fitting in this instance because we can pass a count_total parameter and then call the method WP_User_Query::get_total()