enter Array in usermeta issue

Hello. I'm having difficulty with manipulating arrays in usermeta.

When a user gets created, I add the following array to the database doing:

$myarray = array(
	'10'=>'10',
	'108'=>'108',
	'130'=>'130',
	'281'=>'281',
	'308'=>'308',
	'541'=>'541'
	);
add_user_meta( $user_id, 'mymetafield', $myarray);

That works fine. When I need to check if a value exists as a key in the array keys, I use a function:

function key_compare($keytocheck, $user_id)
{

	$myarray = get_user_meta($user_id, 'metafield');

	if (array_key_exists($keytocheck,$myarray[0])) {

		return true;
	}
	else{
			return false;
	}
}

This also works fine.

However, the issue starts when I try to add a value to the array.

I'd like to add

'102'=>'175'

at the end of the array.

Currently I have:

function update_myarray($key,$value,$user_id)
{
	$myarray = get_user_meta($user_id, 'metafield');

	if(array_key_exists($key,$myarray))
	{
		unset($myarray[$key]);
	}

	$myarray[0][$key] = $key;

	update_user_meta($user_id,'metafield',$myarray); 

}

Unfortunately, that messes up my array because when I use the function key_compare, it doesn't work anymore.

Everything works if I don't use the Update function.

The string value on the database before the udpate is:

a:6:{i:10;s:2:"10";i:108;s:3:"108";i:130;s:3:"130";i:281;s:3:"281";i:308;s:3:"308";i:541;s:3:"541";}

the string value after two updates it becomes:

a:1:{i:0;a:2:{i:0;a:7:{i:10;s:2:"10";i:108;s:3:"108";i:130;s:3:"130";i:281;s:3:"281";i:308;s:3:"308";i:541;s:3:"541";i:293;s:3:"630";}i:157;s:3:"631";}}

I hope someone can help!

Thank you

Giovanni