admin管理员组

文章数量:1389779

When I try to add user meta to empty array as: a:0:{} it's replaced into database as s:6:"a:0:{}";

I just need to save it as I written as a:0:{}

this is my code:

$sassada = get_user_meta($current_user, 'custom_system');   
if(empty($sassada)){
    add_user_meta($sassada, 'custom_system', 'a:0:{}');
}

When I try to add user meta to empty array as: a:0:{} it's replaced into database as s:6:"a:0:{}";

I just need to save it as I written as a:0:{}

this is my code:

$sassada = get_user_meta($current_user, 'custom_system');   
if(empty($sassada)){
    add_user_meta($sassada, 'custom_system', 'a:0:{}');
}
Share Improve this question edited Jun 2, 2017 at 4:12 CodeMascot 4,5372 gold badges15 silver badges25 bronze badges asked Jun 2, 2017 at 3:37 YoguYogu 855 silver badges14 bronze badges 1
  • 1 Why you are putting $sassada as the first parameter of add_user_meta function ? It is wrong cause it should be user ID and secondly you are checking $sassada is empty. That means only empty $sassada goes there. – CodeMascot Commented Jun 2, 2017 at 4:21
Add a comment  | 

1 Answer 1

Reset to default 3

API calls are API calls, not database writes. What and how information is stored in the DB is usually best left as an unknown since, unless explicitly defined in the API, it might change.

Specifically in this case, wordpress will serialize the value being passed, and since you are passing a string it is serialized as a string.

And if what you are after is storing an empty array, just pass an empty array as the value.

本文标签: phpa0 is replaced into database as s6quota0quot