Ask your boss a simple question about how to convert the character set of an array

Source: Internet
Author: User
Ask your boss a simple question, how do you convert the character set of an array?
For strings, there is a mb_convert_encoding () function.

But what about an array? Do you want to cycle through this function:

Array_map (
function ($value) use ($from, $to) {return mb_convert_encoding ($value, $from, $to);},
$input
);


This creates an efficiency problem, and if a big data is weak, it explodes.
Can it be processed at once, with such built-in functions? or other solutions?

Share to:


------Solution--------------------
Array_walk, Array_walk_recursive
But I just got the loop inside.
But it's always going to be faster than your recursive loop.
You can't array_map the light! If the multidimensional array is powerless,
You can also use iterators

In fact, the character set is only required for conversion when input and output
Input (such as a read database), MySQL will give you the character set you need, do not need to convert
Output can be completed via Ob_start
Mb_internal_encoding ("GBK");  
Mb_http_output ("Utf-8"); To output to Utf-8.
Ob_start (' Mb_output_handler '); That's all you need.
And then the output becomes utf-8.
  • Related Article

    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.