PHP array to JSON show a code of Chinese, to explain

Source: Internet
Author: User
Tags php array to json
PHP array to JSON display a code in Chinese, to explain
This post was last edited by wang23412 on 2013-06-09 17:05:27

When I passed the array into JSON format in PHP, I found that Chinese would become a strange encoding. So on the Internet to find a solution, see a lot of people with the following two functions solved:
Function arrayrecursive (& $array, $function, $apply _to_keys_also = False)
{
static $recursive _counter = 0;
if (+ + $recursive _counter > 1000) {
Die (' Possible deep recursion attack ');
}
foreach ($array as $key = = $value) {
if (Is_array ($value)) {
Arrayrecursive ($array [$key], $function, $apply _to_keys_also);
} else {
$array [$key] = $function ($value);
}
if ($apply _to_keys_also && is_string ($key)) {
$new _key = $function ($key);
if ($new _key! = $key) {
$array [$new _key] = $array [$key];
Unset ($array [$key]);
}
}
}
$recursive _counter--;
}

function JSON ($array) {
Arrayrecursive ($array, ' UrlEncode ', true);
$json = Json_encode ($array);
Return UrlDecode ($json);
}

I tested the next really can solve the problem, so carefully studied the next code, found the following code does not know what it means:
$array [$key] = $function ($value);

I output $array[$key] before and after this sentence, and I found this sentence to turn Chinese into a string of codes.
Please explain what $function ($value) means. PHP JSON English Coding

Share to:


------Solution--------------------
Cough you can replace ' $function ' with the value of the parameter $function.
------Solution--------------------
Defined
Function arrayrecursive (& $array, $function, $apply _to_keys_also = False)
$array [$key] = $function($value);

Call
Arrayrecursive ($array, ' UrlEncode', true);

So $array [$key] = $function ($value);
is $array [$key] = UrlEncode ($value);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.