php - Convert string array to array -


unfortunately array saved in database string

'array (     [merid] => 00000     [acqid] => 2121     [orderid] => 94     [responsecode] => 1     [reasoncode] => 1  )' 

i want string converted array original.please

as others have warned horrible idea store data need use in format (is var_dump?). if you're stuck data in format, work given string:

$string = ('array (     [merid] => 00000     [acqid] => 2121     [orderid] => 94     [responsecode] => 1     [reasoncode] => 1  )');  $arrayonly = preg_match('!\(([^\)]+)\)!', $string, $match); $prepared = '$array = array(' . str_replace(['[', ']', "\n"], ['"','"', ","], trim($match[1])) . ');';  eval($prepared); //$array set array 

keep in mind mileage may vary, works specific instance may fail on multidimensional array strings.

if have control of how data stored , want flexible array storage solution, either json_encode or serialize array prior storing. when retrieve data, can json_decode or unserialize original array.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -