3

我们正在使用 PHP、Redis 和 Predis。我们试图在 Redis 中存储一个对象数组,然后检索它。我们注意到数组不能自然地存储在 Redis 中。存储对象数组并稍后检索它的最佳方法是什么?这是我们的对象数组:

"data": [
    {
      "doctor_id": 4, -- Use this id for getting in method get inquiry doctor offers.
      "clinic": "John",
      "distance": "10 mile"
      "city": "Los Angeles",
      "photo": "http://localhost/botox/storage/web/source/1/j4DnpszEy7epcUMf_N8QY0SRhbs7vLRG.png",
      "photos": {
         "http://path/image.jpg",
         "http://path/image.jpg1"
      }

      "price": "123",
      "photo": false,
      "rating": {
        "stars": null,
        "reviews": null
      },
      "add_info"=> "Some information",
      "time_after_create": 942 -- in seconds.
    }
]
4

1 回答 1

1
$dataJSon = json_encode( $data );

然后将 $dataJSon 保存为数据库中的 varchar。

当您检索它时,请使用以下格式:

$data = json_decode( $var_name, TRUE ); // TRUE is needed to return to associative array

要“回显”数组,请回显每个数组元素或在数组上使用 print_r

于 2016-07-13T15:48:15.013 回答