将MySQL数组格式转换为PHP数组

时间:2015-04-25 19:51:46

标签: php mysql wordpress

考虑以下MySQL格式的数组:

a:14:{s:4:"type";s:6:"select";s:12:"instructions";s:0:"";s:8:"required";i:0;s:17:"conditional_logic";i:0;s:7:"wrapper";a:3:{s:5:"width";s:0:"";s:5:"class";s:0:"";s:2:"id";s:0:"";}s:7:"choices";a:17:{s:14:"2.25mm (B - 1)";s:14:"2.25mm (B - 1)";s:14:"2.75mm (C - 2)";s:14:"2.75mm (C - 2)";s:14:"3.25mm (D - 3)";s:14:"3.25mm (D - 3)";s:13:"3.5mm (E - 4)";s:13:"3.5mm (E - 4)";s:14:"3.75mm (F - 5)";s:14:"3.75mm (F - 5)";s:11:"4mm (G - 6)";s:11:"4mm (G - 6)";s:9:"4.5mm (7)";s:9:"4.5mm (7)";s:11:"5mm (H - 8)";s:11:"5mm (H - 8)";s:13:"5.5mm (I - 9)";s:13:"5.5mm (I - 9)";s:12:"6mm (J - 10)";s:12:"6mm (J - 10)";s:16:"6.5mm (K - 10.5)";s:16:"6.5mm (K - 10.5)";s:12:"8mm (L - 11)";s:12:"8mm (L - 11)";s:14:"9mm (M/N - 13)";s:14:"9mm (M/N - 13)";s:15:"10mm (N/P - 15)";s:15:"10mm (N/P - 15)";s:10:"15mm (P/Q)";s:10:"15mm (P/Q)";s:8:"16mm (Q)";s:8:"16mm (Q)";s:8:"19mm (S)";s:8:"19mm (S)";}s:13:"default_value";a:0:{}s:10:"allow_null";i:0;s:8:"multiple";i:0;s:2:"ui";i:0;s:4:"ajax";i:0;s:11:"placeholder";s:0:"";s:8:"disabled";i:0;s:8:"readonly";i:0;}

我如何将这些数据提供给PHP数组?

使用$ wpdb-> get_results在WordPress环境中抓取此数据,并且数据不断以编码的MySQL格式返回。我试过json_decode,但它似乎不起作用。任何洞察力都赞赏。

1 个答案:

答案 0 :(得分:3)

如果您使用unserializereference),您将获得以下数组:

Array
(
    [type] => select
    [instructions] => 
    [required] => 0
    [conditional_logic] => 0
    [wrapper] => Array
        (
            [width] => 
            [class] => 
            [id] => 
        )

    [choices] => Array
        (
            [2.25mm (B - 1)] => 2.25mm (B - 1)
            [2.75mm (C - 2)] => 2.75mm (C - 2)
            [3.25mm (D - 3)] => 3.25mm (D - 3)
            [3.5mm (E - 4)] => 3.5mm (E - 4)
            [3.75mm (F - 5)] => 3.75mm (F - 5)
            [4mm (G - 6)] => 4mm (G - 6)
            [4.5mm (7)] => 4.5mm (7)
            [5mm (H - 8)] => 5mm (H - 8)
            [5.5mm (I - 9)] => 5.5mm (I - 9)
            [6mm (J - 10)] => 6mm (J - 10)
            [6.5mm (K - 10.5)] => 6.5mm (K - 10.5)
            [8mm (L - 11)] => 8mm (L - 11)
            [9mm (M/N - 13)] => 9mm (M/N - 13)
            [10mm (N/P - 15)] => 10mm (N/P - 15)
            [15mm (P/Q)] => 15mm (P/Q)
            [16mm (Q)] => 16mm (Q)
            [19mm (S)] => 19mm (S)
        )

    [default_value] => Array
        (
        )

    [allow_null] => 0
    [multiple] => 0
    [ui] => 0
    [ajax] => 0
    [placeholder] => 
    [disabled] => 0
    [readonly] => 0
)