Try serialize(). It converts an array into a string format, you can then use unserialize() to convert it back to an array. Scripts like WordPress use this to save multiple values to a single database field.
You can also use json_encode() as Rob said, which maybe useful if you want to read the cookie in javascript.
You can also try to write different elements in different cookies. Cookies names can be set as array names and will be available to your PHP scripts as arrays but separate cookies are stored on the user's system. Consider explode() to set one cookie with multiple names and values. It is not recommended to use serialize() for this purpose, because it can result in security holes. Look at setcookie PHP function for more details
Try
serialize()
. It converts an array into a string format, you can then useunserialize()
to convert it back to an array. Scripts like WordPress use this to save multiple values to a single database field.You can also use
json_encode()
as Rob said, which maybe useful if you want to read the cookie in javascript.You can also try to write different elements in different cookies. Cookies names can be set as array names and will be available to your PHP scripts as arrays but separate cookies are stored on the user's system. Consider explode() to set one cookie with multiple names and values. It is not recommended to use serialize() for this purpose, because it can result in security holes. Look at setcookie PHP function for more details