Convert MySQL array format to PHP array

Consider the following MySQL formatted array:

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;}

How might I go about feeding this data into a PHP array?

Read More

This data was grabbed in a WordPress environment using $wpdb->get_results, and the data keeps coming back in an encoded MySQL format. I tried json_decode but it doesn’t seem to work. Any insight appreciated.

Related posts

Leave a Reply

1 comment

  1. If you use unserialize (reference) you will get the following array:

    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
    )