Home > Backend Development > PHP Tutorial > 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
Release: 2016-07-25 08:57:03
Original
896 people have browsed it
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.



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template