PHP Compress array of bits into shortest string possible
问题 I have an array that contains values of 1 or 0 representing true or false values. e.g. array(1,0,0,1,0,1,1,1,1); I want to compress/encode this array into the shortest string possible so that it can be stored within a space constrained place such as a cookie. It also need to be able to be decoded again later. How do I go about this? ps. I am working in PHP 回答1: Here is my proposal: $a = array(1,0,0,1,0,1,1,1,1,1,0,0,1,0,1,1,1,1,1,0,0,1,0,1,1,1,1); $compressed = base64_encode(implode('', array