PHP secondary array conversion json

WBOY
Release: 2016-07-29 08:58:24
Original
1207 people have browsed it

PHP provides functions to directly convert array into json

<code>json_encode(<span>$param_array</span>);</code>
Copy after login

How to deal with the following nesting?

<code>{
    <span>"appid"</span>: <span>"1500001105"</span>,
    <span>"nonce"</span>: <span>32490</span>,
    <span>"timestamp"</span>: <span>1458195253</span>,
    <span>"signature"</span>: <span>"bf13fe77f46a96edba1a0e2b84fce66580b2f50b"</span>,
    <span>"param"</span>: {
        <span>"userid"</span>: <span>"bonnie"</span>
    }
}</code>
Copy after login

First form a secondary array, and then call json_encode to convert.

<code><span>$param</span> = <span>array</span>(
    <span>'userid'</span>=><span>'bonnie'</span>
);
<span>$params</span> = <span>array</span>(
    <span>'appid'</span>=><span>'1500001105'</span>,
    <span>'nonce'</span>=><span>$nonce</span>,
    <span>'timestamp'</span>=><span>$timestamp</span>,
    <span>'signature'</span>=><span>$signature</span>,
    <span>'param'</span>=><span>$param</span>,
);
<span>$params_json</span> = json_encode(<span>$params</span>);</code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces PHP secondary array conversion to json, including the content. 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