title: Save $_SESSION from a list of checkbox data?
body: <p>Im trying to save $_SESSION data to keep checked values on page refresh, I have some code written up but I am missing a piece.</p>
  
  <p><strong>Session Code:</strong></p>
  
  <pre><code> session_start();
   if(isset($_POST['submit'])) {
  
     //user posted variable
     $checks = $_POST['personalization_result'];
  
  
     if(isset($_POST['personalization_result'])) {   
      $_SESSION['value'] = $_POST['personalization_result']; } 
     else {
      $_SESSION['value'] = '';  
     }
   }
  </code></pre>
  
  <p><strong>Form Code:</strong></p>
  
  <pre><code> &lt;form action="" method="post" id="question-form"&gt; 
  
       &lt;input type="hidden" name="submit" value="1"&gt;
  
         &lt;li&gt;
         &lt;input name="personalization_result[memory_0]" type="hidden"  class="&lt;?php echo $_SESSION['value']['memory_0'] ?&gt;" value="0"  /&gt;
         &lt;input name="personalization_result[memory_0]" type="checkbox" value="1" id="personalization_result_memory_0" /&gt;
         &lt;/li&gt; 
  
         &lt;li&gt;
         &lt;input name="personalization_result[memory_1]" type="hidden"  class="&lt;?php echo $_SESSION['value']['memory_1'] ?&gt;" value="0"  /&gt;
         &lt;input name="personalization_result[memory_1]" type="checkbox" value="1" id="personalization_result_memory_1" /&gt;
         &lt;/li&gt;
  
        //There are many checkboxes, this is just two for demo purposes
  
       &lt;input class="submit" type="submit" value="Send" /&gt;
  
   &lt;/form&gt;
  </code></pre>
  
  <p>For testing I am echoing <code>$_SESSION['value']['memory_0']</code> &amp;&amp; <code>$_SESSION['value']['memory_1']</code>inside the hidden input, they return properly, if the input is checked the class is 1, if it's unchecked the class is 0. </p>
  
  <p>I am not sure the best way to say if it = 1 then echo <code>checked="checked"</code></p>
  
  <p><strong>My shotty attempt:</strong></p>
  
  <pre><code>&lt;input name="personalization_result[memory_0]" type="hidden"  class="&lt;?php echo $_SESSION['value']['memory_0'] ?&gt;" value="0"  /&gt;
  &lt;input name="personalization_result[memory_0]" type="checkbox" value="1" id="personalization_result_memory_0" &lt;?php if($_SESSION['value']['memory_0'] = 1) {echo 'checked="checked"';} ?&gt; /&gt;
  </code></pre>
  
  <p>This returns an error "Cannot use a scalar value as an array", that and I dont like how thats written up.</p>
  
  <p>So with all the given information, whats the best way to write if my value = 1 return <code>checked="checked"</code>?</p>