Unsetting index in array turns it to an object

前端 未结 2 1411
感情败类
感情败类 2021-01-21 09:42

So I have a JSON document I\'m storing in CouchDB. Here\'s the important part of it:

\"games\": {
   \"creator\": [
       \"cf86d68b24c1bbf22702356572027642\",         


        
相关标签:
2条回答
  • 2021-01-21 10:12

    I fixed it like this:

    unset($user->games->creator[1]);
    $user->games->creator = array_values($user->games->creator);
    
    0 讨论(0)
  • 2021-01-21 10:30

    Instead of using unset, use array_splice. This will automatically adjust the array indexes:

    array_splice($user->games->creator, 1, 1);
    
    0 讨论(0)
提交回复
热议问题