_php tutorial on applying PHP serialized array techniques

Source: Internet
Author: User

Serialize---------to format an array as an ordered string
Unserialize-----to restore arrays

Examples of PHP serialized array tests:

$test = Array ("A" =>0, "B" =>0, "C" =>0);
$test 2 = ";
$test 2=serialize ($test);
echo $test 2;
echo "";
Print_r (Unserialize ($test 2));

PHP Serialization Array uses:

In my personal experience, I mainly deal with array transfer, array repository operation.

For example I have an array that needs to be passed to the next page, if you don't want to use Seesion/cookie, then you can take advantage of that function, pass it, and then restore it.
For example, when I do the directory of the site, there is a score, divided into high praise, evaluation, bad reviews. Then my database gives this feature a field that is designed to be a long character type. Combine three comments into an array of:

Array
' A ' + 0,//rated 0
' B ' + = 0,//rating 0
' C ' + 0//difference rating 0
)

After converting it with the Serialize function: a:3:{s:1: "a"; I:0;s:1: "B"; I:0;s:1: "C"; i:0;}, and then the database exists. Do not forget to use the Unserialize function to convert to an array when you remove it.

This is the correct way to use the PHP serialized array.


http://www.bkjia.com/PHPjc/446013.html www.bkjia.com true http://www.bkjia.com/PHPjc/446013.html techarticle serialize---------to format the array into an ordered string unserialize-----to restore an array of arrays of PHP serialized array Test instances: $test = Array (a=0,b=0,c=0); $test 2 = "; $t ...

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