Answer the question
In order to leave comments, you need to log in
How to pack an array with string values using pack()?
// Создаю массив
$aYearColor = array_fill(0,366,'#FFFFFF');
// Запаковываю его
$aYearColorBlob = pack('a*', ...$aYearColor);
// Распаковываю
unpack('a*', $aYearColorBlob);
$aYearOrder = array_fill(0,366,0);
$aYearOrderBlob = pack('i*', ...$aYearOrder);
unpack('i*', $aYearOrderBlob);
For a, A, h, H, the number of repetitions determines how many characters are taken
from one data argument
Answer the question
In order to leave comments, you need to log in
The string does not have a fixed length, unlike other types. pack() does not add the result of string lengths or delimiters, so the result of packing strings is the same as if you had just concatenated them. Accordingly, 'a*' when packed means "one string of arbitrary length to the end".
unpack() will also not be able to automatically split the resulting string into the original substrings, it simply will not have guidelines for this.
Maybe you should switch to JSON or serialize?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question