2015-04-25 59 views
1

考慮以下MySQL的格式化數組:轉換MySQL的陣列格式PHP陣列

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,但它似乎沒有工作。任何洞察讚賞。

+2

該數據序列化:)使用unserialize:http://php.net/manual/en/function.unserialize.php – Marc

+0

DOH! - 我現在無法相信自己。我剛剛搜索了20分鐘的各種谷歌搜索,我已經用了很多東西。謝謝你清理那個。 –

回答

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 
)