Unfortunately the array is saved in database as string
'Array
(
[MerID] => 00000
[AcqID] => 2121
[OrderID] => 94
[ResponseCode] => 1
[ReasonCode] => 1
)'
I want this string to be converted to array as original.Please Help
Unfortunately the array is saved in database as string
'Array
(
[MerID] => 00000
[AcqID] => 2121
[OrderID] => 94
[ResponseCode] => 1
[ReasonCode] => 1
)'
I want this string to be converted to array as original.Please Help
As others have warned you it is a horrible idea to store data you actually need to use in this format (is that from a var_dump?). If you're already stuck with data in this format, this will work for the 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 is now set to your array
Keep in mind this your mileage may vary, this works for this specific instance but may fail on multidimensional array strings.
If you do have control of how the data is actually stored and want a flexible array storage solution, look to either json_encode or serialize the array prior to storing. Then when you retrieve the data, you can json_decode or unserialize to get the original array.