Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are mainly two possible ways to achieve this:</p> <ol> <li><p>Serialize the data in some way:</p> <pre><code>$postvalue = serialize($array); // client side $array = unserialize($_POST['result']; //server side </code></pre> <p>And then you can unserialize the posted values with <code>unserialize($postvalue)</code> Further information on this is <a href="http://php.net/manual/en/function.serialize.php">here in the php manuals</a>.</p> <p>Alternativley you can use the <code>json_encode()</code> and <code>json_decode()</code> functions to get a json formatted serialized string. You could even shrink the transmitted data with <code>gzcompress()</code> (note that this is performance intensive) and secure the transmitted data with <code>base64_encode()</code> (to make your data survive in non-8bit clean transport layers) This could look like this:</p> <pre><code>$postvalue = base64_encode(json_encode($array)); //client side $array = json_decode(base64_decode($_POST['result'])); //server side </code></pre> <p>A not recommended way to serialize your data (but very cheap in performance) is to simply use <code>implode()</code> on your array to get a string with all values separated by some specified character. On serverside you can retrieve the array with <code>explode()</code> then. But note that you shouldn't use a character for separation that occurs in the array values (or then escape it) and that you cannot transmit the array keys with this method.</p></li> <li><p>Use the properties of special named input elements:</p> <pre><code>$postvalue = ""; foreach ($array as $v) { $postvalue .= '&lt;input type="hidden" name="result[]" value="' .$v. '" /&gt;'; } </code></pre> <p>Like this you get your entire array in the <code>$_POST['result']</code> variable if the form is sent. Note that this doesn't transmit array keys. However you can achieve this by using <code>result[$key]</code> as name of each field.</p></li> </ol> <p>Every of this methods got their own advantages and disadvantages. What you use is mainly depending on how large your array will be, since you should try to send a minimal amount of data with all of this methods.</p> <p>An other way to achieve the same is to store the array in a server side session instead of transmitting it client side. Like this you can access the array over the <code>$_SESSION</code> variable and don't have to transmit anything over the form. For this have a look at <a href="http://ch.php.net/manual/en/session.examples.basic.php">a basic usage example of sessions on php.net</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload