Conversion of PHP Array to Javascript

WBOY
Release: 2016-07-30 13:29:48
Original
802 people have browsed it

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>
Copy after login

Result:

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

3.Javascript JSON to Array

jquery receives JSON string

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

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.

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!