Home > Article > Backend Development > How to convert php string content to an array when it is an array
This article introduces how to convert the format into an actual array when the content of the string is an array. Friends in need can refer to it.
There is such a string whose stored content is an array, for example: $str = "array( 'USD'=>'1', 'GBP'=>'0.6494', 'EUR'=>'0.7668' ,'JPY'=>'82.8150','RMB'=>'6.6480' )";Existing $str, the content is data in array form. Requires conversion to array, for example: $arr = array( 'USD'=>'1', 'GBP'=>'0.6494', 'EUR'=>'0.7668' ,'JPY'=>'82.8150','RMB'=>'6.6480' ) ;Solution: eval("$arr = ".$str.'; '); By executing the above function, you can get the array $arr as an array of string $str data, similar to using eval in js. |