从单个字段解析数组

时间:2015-05-27 19:36:19

标签: php arrays

我有一个表,其中包含一个包含似乎是数组的字段。有没有一种简单的方法可以将其转换为我可以使用的数组?

SELECT data FROM exp_cartthrob_item_options_options

Print_r(data); 

返回以下内容:

a:19:{i:0;a:6:{s:12:"option_value";s:18:"cp-1202-faraglioni";s:11:"option_name";s:16:"1202 Faraglioni ";s:5:"price";s:0:"";s:5:"color";s:5:"Putty";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:1;a:6:{s:12:"option_value";s:21:"cp-1203-scala-fenicia";s:11:"option_name";s:18:"1203 Scala Fenicia";s:5:"price";s:0:"";s:5:"color";s:5:"Brown";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:2;a:6:{s:12:"option_value";s:19:"cp-1204-castiglione";s:11:"option_name";s:17:"1204 Castiglione ";s:5:"price";s:0:"";s:5:"color";s:5:"Beige";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:3;a:6:{s:12:"option_value";s:19:"cp-1205-villa-jovis";s:11:"option_name";s:17:"1205 Villa Jovis ";s:5:"price";s:0:"";s:5:"color";s:3:"Tan";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:4;a:6:{s:12:"option_value";s:16:"cp-1207-anacapri";s:11:"option_name";s:14:"1207 Anacapri ";s:5:"price";s:0:"";s:5:"color";s:10:"Warm Beige";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:5;a:6:{s:12:"option_value";s:20:"cp-1208-monte-solaro";s:11:"option_name";s:17:"1208 Monte Solaro";s:5:"price";s:0:"";s:5:"color";s:10:"Warm Beige";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:6;a:6:{s:12:"option_value";s:13:"cp-BLCK-black";s:11:"option_name";s:10:"BLCK Black";s:5:"price";s:0:"";s:5:"color";s:6:"Black ";s:13:"grain_texture";s:5:"Full ";s:6:"finish";s:5:"Light";}i:17;a:6:{s:12:"option_value";s:21:"cd-0061-mexican-ochre";s:11:"option_name";s:18:"0061 Mexican Ochre";s:5:"price";s:0:"";s:5:"color";s:10:"Warm Beige";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:18;a:6:{s:12:"option_value";s:12:"cd-0063-soho";s:11:"option_name";s:9:"0063 SoHo";s:5:"price";s:0:"";s:5:"color";s:6:"Orange";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:19;a:6:{s:12:"option_value";s:13:"cd-0064-cocoa";s:11:"option_name";s:10:"0064 Cocoa";s:5:"price";s:0:"";s:5:"color";s:5:"Brown";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:20;a:6:{s:12:"option_value";s:18:"cd-0065-brownstone";s:11:"option_name";s:15:"0065 Brownstone";s:5:"price";s:0:"";s:5:"color";s:5:"Brown";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:21;a:6:{s:12:"option_value";s:13:"cd-0066-tabac";s:11:"option_name";s:10:"0066 Tabac";s:5:"price";s:0:"";s:5:"color";s:5:"Brown";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:22;a:6:{s:12:"option_value";s:18:"cd-0067-toro-black";s:11:"option_name";s:15:"0067 Toro Black";s:5:"price";s:0:"";s:5:"color";s:5:"Black";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:23;a:6:{s:12:"option_value";s:23:"cd-0068-sun-dried-brick";s:11:"option_name";s:20:"0068 Sun-Dried Brick";s:5:"price";s:0:"";s:5:"color";s:12:"Medium Brown";s:13:"grain_texture";s:5:"Full ";s:6:"finish";s:5:"Light";}i:24;a:6:{s:12:"option_value";s:14:"cd-0069-gothic";s:11:"option_name";s:11:"0069 Gothic";s:5:"price";s:0:"";s:5:"color";s:5:"Brown";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:25;a:6:{s:12:"option_value";s:23:"cd-0070-rembrandt-brown";s:11:"option_name";s:23:"0070 Rembrandt Brown ";s:5:"price";s:0:"";s:5:"color";s:12:"Medium Brown";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:27;a:6:{s:12:"option_value";s:15:"cd-0078-pompeii";s:11:"option_name";s:12:"0078 Pompeii";s:5:"price";s:0:"";s:5:"color";s:3:"Red";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:30;a:6:{s:12:"option_value";s:21:"cd-0082-gulmard-green";s:11:"option_name";s:18:"0082 Gulmard Green";s:5:"price";s:0:"";s:5:"color";s:10:"Dark Green";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}i:31;a:6:{s:12:"option_value";s:21:"cd-0084-prussian-blue";s:11:"option_name";s:18:"0084 Prussian Blue";s:5:"price";s:0:"";s:5:"color";s:9:"Dark Blue";s:13:"grain_texture";s:4:"Full";s:6:"finish";s:5:"Light";}}

1 个答案:

答案 0 :(得分:2)

是的,您可以使用unserialize()来实现这一目标:

SELECT data FROM exp_cartthrob_item_options_options

$array = unserialize($data);
var_dump($array);