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(
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;
			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


at the end of the array.

Currently I have:

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


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



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:


the string value after two updates it becomes:


I hope someone can help!

Thank you