Home >Backend Development >PHP Tutorial >Share tips for turning PHP arrays into JSON arrays_PHP Tutorial

Share tips for turning PHP arrays into JSON arrays_PHP Tutorial

WBOY
WBOYOriginal
2016-07-15 13:32:58846browse

Today, we will introduce to you a specific implementation method of

PHP array into JSON array:

1. On the server side The serialized characters are converted from GBK to UTF-8 required by soap and the result is returned:

  1. $str =array("text");
  2. $ serializeserialize_str =
    serialize($str);
  3. $res = iconv("GBK","UTF-8 "
    ,$serialize_str);
  4. return $res;

2. Get the result on the client side Then convert UTF-8 to GBK required by the page, and then deserialize and print the array to be a normal array without Chinese garbled characters:

<ol class="dp-xml">
<li class="alt"><span><span>$</span><span class="attribute-value">iconv</span><span class="attribute">iconv_str</span><span> = iconv<br>("UTF-8","GBK",$res);   </span></span></li>
<li>
<span>$</span><span class="attribute">arr</span><span> = </span><span class="attribute-value">unserialize<br></span><span>($iconv_str);   </span>
</li>
<li class="alt"><span>var_dump($arr);  </span></li>
</ol>

The above code example is all about turning a PHP array into a JSON array. implementation process.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446098.htmlTechArticleToday, we will introduce to you the specific implementation method of turning a PHP array into a JSON array: 1. In the service The end converts the serialized characters from GBK to UTF-8 required by soap and returns the result:...
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