我已将数据库中的数组存储为字符串,如何检索该数组?

时间:2016-02-09 09:18:22

标签: php mysql arrays

我已在数据库中将此数组保存为String

Array
(
    [item_number1] =>1
    [payment_date] => 04:21:34 Dec 06, 2014 PST
    [payment_status] => Completed
    [first_name] => sdfsd
    [last_name] => parsdfsdandekar
    [quantity1] => 1
)

现在,我想使用所有数组值。

如何获取它们?

1 个答案:

答案 0 :(得分:0)

在将数组保存到数据库之前首先使用JSON_ENCODE,如果要再次获取内容,请使用JSON_DECODE

     $arr = array(
        "item_number1" => "1",
        "payment_date" => "04:21:34 Dec 06, 2014 PST",
        "payment_status" => "Completed",
        "first_name" => "sdfsd",
        "last_name" => "parsdfsdandekar",
        "quantity1" => "1"
     );

     echo json_encode($arr);

JSON_ENCODE之后的结果(数组到JSON字符串):

{ "item_number1" => "1", "payment_date" => "04:21:34 Dec 06, 2014 PST", "payment_status" => "Completed", "first_name" => "sdfsd", "last_name" => "parsdfsdandekar", "quantity1" => "1" }