最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - a:0:{} is replaced into database as s:6:"a:0:{}";

programmeradmin1浏览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:{}');
}

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.

发布评论

评论列表(0)

  1. 暂无评论