Home  >  Article  >  Backend Development  >  How to convert php string content to an array when it is an array

How to convert php string content to an array when it is an array

WBOY
WBOYOriginal
2016-07-25 08:57:03869browse
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.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn