Is there a better way or function to convert an array to a string store (the smaller the string, the better)?

Source: Internet
Author: User
Keywords Php
I tried to save the array information to the database. serializeAnd json_encodeserializeThan json_encodeThe string length of the conversion is less than 1/3, but want to ask PHPThere's nothing else. functionOr Methodcan be converted. less-length strings

Reply content:

Because to save the array information to the database, I tried to use serialize and json_encode , serialize json_encode 1/3 less than the conversion string length, but there is PHP no other function or method to ask Can I convert a string of less length ?

No need, Json_encode is actually very good, especially considering that the data may be called directly by the front end. If you have enough database space to buy a hard disk, this is the best advice.
The more you compress, the more computationally you need, the more hassle you'll get when you decompress, and the less space-saving performance you'll never get.

You can search your own string compression algorithms, such as http://www.jb51.net/article/46144.htm

Typically, the CPU time is much more expensive than disk space, except for special requirements, so there is no need to waste CPU time for disk space.
Compressing and decompressing strings is time-consuming and not worth it.

The main thing is to look at the requirements, your string compression is used to implement what content, if it is to communicate with other parts, then JSON is a better way to implement. If it is for storage, then forget it.

Implode (Separator,array)

Messagepack is an efficient binary serialization format. It allows you to exchange data between languages like JSON. But it's faster and smaller than JSON.

  • 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.