Home  >  Article  >  Backend Development  >  Conversion of PHP Array to Javascript

Conversion of PHP Array to Javascript

WBOY
WBOYOriginal
2016-07-30 13:29:48825browse

Great programmers start with a set of pages.

1. The process of converting from PHP Array to Javascript Array

PHP Array -> PHP JSON -> Transfer -> Javascript String ->Javascript Array

2.PHP Array to JSON

<code><span>$qps_data</span> = <span>array</span>(
<span>'1440743647000'</span>=><span>array</span>(<span>'x'</span>=><span>'1440743647000'</span>,<span>'y'</span>=><span>'16'</span>),
<span>'1440743647000'</span>=><span>array</span>(<span>'x'</span>=><span>'1440743647000'</span>,<span>'y'</span>=><span>'16'</span>)
);
<span>echo</span> json_encode(<span>$qps_data</span>);</code>

Result:

<code>{<span>"1440743647000"</span>:{<span>"x"</span>:<span>"1440743647000"</span>,<span>"y"</span>:<span>"16"</span>}}</code>

3.Javascript JSON to Array

jquery receives JSON string

<code>arrayObj = <span>eval</span>(json_string);
console.<span>log</span>(arrayObj);</code>

Copyright statement: This article is an original article by the blogger and may not be reproduced without the permission of the blogger.

The above introduces the conversion of PHP Array to Javascript, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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
Previous article:PHP eval functionNext article:PHP eval function