title: Caesar Cipher PHP
body: <p>i get 2 errors from my code. Or 1 error and 1 notice.</p>
  <p>Heres the Notice and the problem</p>
  <blockquote>
  <p>Notice: Undefined offset: 0 in F:\Xampp\htdocs\Encryption\result.php on line 19</p>
  <p>Warning: in_array() expects parameter 2 to be array, string given in F:\Xampp\htdocs\Encryption\result.php on line 19</p>
  </blockquote>
  <p>And here is my code</p>
  <p>Index.php</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id=&quot;encrypt&quot; style=&quot;position:absolute; left:20%; top:25%;&quot;&gt;
      &lt;form method=&quot;post&quot; action=&quot;result.php&quot;&gt;
      &lt;textarea rows=&quot;4&quot; cols=&quot;50&quot; name=&quot;toEncrypt&quot;&gt;Enter message to encrypt&lt;/textarea&gt;
      &lt;br/&gt;
      &lt;input type=&quot;submit&quot; name=&quot;encrypt&quot; value=&quot;Encrypt&quot;&gt;
      &lt;/form&gt;
      &lt;/div&gt;
      &lt;div id=&quot;decrypt&quot; style=&quot;position:absolute; right:20%; top:25%;&quot;&gt;
      &lt;form method=&quot;post&quot; action=&quot;result.php&quot;&gt;
      &lt;textarea rows=&quot;4&quot; cols=&quot;50&quot; name=&quot;toDecrypt&quot;&gt;Enter message to decrypt&lt;/textarea&gt;
      &lt;br/&gt;
      &lt;input type=&quot;submit&quot; name=&quot;decrypt&quot; value=&quot;Decrypt&quot;&gt;
      &lt;/form&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>And this is my PHP file.</p>
  <pre><code>&lt;?php
  $toEncrypt = $_POST['toEncrypt'];
  //$toDecrypt = $_POST['toDecrypt'];
  $key = array(
  &quot;A&quot; =&gt; &quot;B&quot;, &quot;B&quot; =&gt; &quot;C&quot;,&quot;C&quot; =&gt; &quot;D&quot;, &quot;D&quot; =&gt; &quot;E&quot;,&quot;E&quot; =&gt; &quot;F&quot;,&quot;F&quot; =&gt; &quot;G&quot;,
  &quot;G&quot; =&gt; &quot;H&quot;, &quot;H&quot; =&gt; &quot;I&quot;, &quot;I&quot; =&gt; &quot;J&quot;, &quot;J&quot; =&gt; &quot;K&quot;,&quot;K&quot; =&gt; &quot;L&quot;,
  &quot;L&quot; =&gt; &quot;M&quot;,&quot;M&quot; =&gt; &quot;N&quot;, &quot;N&quot; =&gt; &quot;O&quot;, &quot;O&quot; =&gt; &quot;P&quot;, 
  &quot;P&quot; =&gt; &quot;Q&quot;,&quot;Q&quot; =&gt; &quot;R&quot;, &quot;R&quot; =&gt; &quot;S&quot;,&quot;S&quot; =&gt; &quot;T&quot;,&quot;T&quot; =&gt; &quot;U&quot;, 
  &quot;U&quot; =&gt; &quot;V&quot;, &quot;V&quot; =&gt; &quot;W&quot;, &quot;W&quot; =&gt; &quot;X&quot;, &quot;X&quot; =&gt; &quot;Y&quot;,
  &quot;Y&quot; =&gt; &quot;Z&quot;, &quot;Z&quot; =&gt; &quot;Å&quot;, &quot;Å&quot; =&gt; &quot;Ä&quot;, &quot;Ä&quot; =&gt; &quot;Ö&quot;, &quot;Ö&quot; =&gt; &quot;A&quot;
  );
  
  //$text2 = $toDecrypt;
  
  $length=strlen($toEncrypt);
  $newstr='';
  for ($i = 0; $i &lt; $length; $i++) 
  {
  if (is_array($key) &amp;&amp; in_array($toEncrypt[$i], $key[$i]))
  {
  $newstr=$key[$i];
  }
  }
  
  echo $newstr;
  </code></pre>
  <p>I can't figure out what's wrong, i think it's too obvious for me too spot it, Thanks in advance.</p>