Is this a decent way to achieve it? I'm not really a huge fan of eval() but it seems to be working well. Are there any possible problems with this solution potentially with long strings that span multiple lines perhaps?
PHP Code:
function dictionaryToArrray() {
$args = func_get_args();
if(empty($args)) {
return array();
} else {
eval('$properties = array('.rtrim(preg_replace('/(.*?):(\".*?\"|[0-9.]*?)(;|$)/s','\'$1\'=>$2,',implode(';',$args)),',').');');
return $properties;
}
}
echo '<pre>',print_r(dictionaryToArrray('a:"My String"','b:45','c:"Some other info"','d:6.4')),'</pre>';
HTML Code:
Array
(
[a] => My String
[b] => 45
[c] => Some other info
[d] => 6.4
)
Bookmarks