There are basically two possible ways to achieve this:
Serializing data in some way:
$postvalue = serialize($array); // Client side $array = unserialize($_POST['result']; // Server side
And then you can deserialize the published values ββwith unserialize($postvalue) . Further information on this is here in the PHP manuals .
Alternatively, you can use the json_encode() and json_decode() functions to get a serialized string in JSON format. You could even reduce the transmitted data with gzcompress() (note that this is gzcompress() performance) and protect the transmitted data with base64_encode() (so that your data survives in non-8-bit pure transport layers). It might look like this:
$postvalue = base64_encode(json_encode($array)); // Client side $array = json_decode(base64_decode($_POST['result'])); // Server side
The not recommended way to serialize your data (but very cheap in terms of performance) is to simply use implode() in your array to get a string with all values ββseparated by any given character. On the server side, you can get the array using explode() . But note that you should not use a character to separate that occurs in the values ββof the array (or then escape it), and that you cannot pass the keys of the array using this method.
Use the properties of special named input elements:
$postvalue = ""; foreach ($array as $v) { $postvalue .= '<input type="hidden" name="result[]" value="' .$v. '" />'; }
Thus, you will receive the entire array in the variable $_POST['result'] if the form is submitted. Note that this does not pass array keys. However, you can achieve this by using result[$key] as the name of each field.
Each of these methods has its advantages and disadvantages. What you use mostly depends on how big your array will be, since you should try to send a minimal amount of data with all of these methods.
Another way to achieve the same thing is to save the array in a session on the server side, rather than passing it on the client side. Thus, you can access the array through the $_SESSION variable and do not have to pass anything in form. To do this, take a look at a basic example of using sessions on php.net .
s1lence Jul 01 2018-11-11T00: 00Z
source share