Home > Article > Backend Development > PHP secondary array conversion json
PHP provides functions to directly convert array into json
<code>json_encode(<span>$param_array</span>);</code>
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>
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>').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.