A photo album function module is being developed recently. The process is probably to generate an array of batch uploaded image data and then store the array in a field of the data table, when reading images, traverse the array to browse multiple images. However, arrays cannot be read and written directly to the database. Therefore, you must convert the array into strings before saving it to the database. The string retrieved from the database must be restored to an array for traversal and reading. Previously, I thought that such a process of mutual conversion would need to be processed by writing a very complex function, and later I proved to be a multi-filter. Remember that PHP has a built-in function that is currently developing an album function module. The process is probably like: generate an array of batch uploaded image data, and then save the array to a field in the data table, when reading images, traverse the array to browse multiple images.
However, arrays cannot be read and written directly to the database. Therefore, you must convert the array into strings before saving it to the database. The string retrieved from the database must be restored to an array for traversal and reading. Previously, I thought that such a process of mutual conversion would need to be processed by writing a very complex function, and later I proved to be a multi-filter. Remember that PHP has a built-in function serialize () that can process Object serialization. After turning over the php manual, the serialize () and unserialize () can also serialize arrays! Now let's take a look at its usage:
Serialize () -- returns a string that contains the byte stream that represents value and can be stored anywhere. This facilitates storing or passing PHP values without losing their types and structures.
Unserialize () -- operate a single serialized variable and convert it back to the PHP value. The returned value is the converted value, which can be integer, float, string, array, or object. If the passed string cannot be deserialized, FALSE is returned.
Below are my debugging records:
'1, jpg ', '1' => '2, jpg', '2' => '3, jpg '); $ picarray = serialize ($ picarray ); // serialize the array and store it to the database print