title: PHP: Check if Key is equal to string
body: <p>I'm working with a two-dimensional array, and as I'm iterating through each index of this array, I'm trying to check if the current key is equal to a string.</p>
  
  <p>Here's how I'm trying to do it:</p>
  
  <pre><code>foreach($_POST['items'] as $index =&gt; $item){
  
      $key = key($item);
  
      if($key == 'image'){
          echo 'hello';
      }
  
  }
  </code></pre>
  
  <p>This throws the error  <strong>Invalid argument supplied for foreach()</strong> </p>
  
  <p>How do you check if the current key is equal to a particular string?</p>
  
  <p>var_dump</p>
  
  <pre><code>array(2) { 
      [0]=&gt; array(1) { ["paragraph"]=&gt; string(4) "paragraph 1" } 
      [1]=&gt; array(1) { ["paragraph"]=&gt; string(4) "paragraph 2" } 
  } 
  array(2) { 
      [0]=&gt; array(1) { ["paragraph"]=&gt; string(4) "paragraph 3" } 
      [1]=&gt; array(1) { ["paragraph"]=&gt; string(4) "paragraph 4" } 
  }
  </code></pre>
  
  <p>Here is the element within the form with name <code>image</code>:</p>
  
  <pre><code>&lt;div&gt;&lt;input type="file" name="items[][image]" id="uploadImage" multiple&gt;&lt;/div&gt;
  </code></pre>
  
  <p><strong>var_dump of dynamic form with 1 image input followed by 1 paragraph input</strong></p>
  
  <pre><code>array(1) { 
      [0]=&gt; array(1) { ["paragraph"]=&gt; string(11) "paragraph 1" } 
  } 
  </code></pre>
  
  <p><code>var_dump</code> is not seeing the input with name <code>image</code>???</p>
  
  <p><strong>Here is the form</strong> Its contents are dynamically added from <code>&lt;script&gt;</code></p>
  
  <pre><code>&lt;form method="post" action="insert.php" enctype="multipart/form-data"&gt;
  
          &lt;textarea name="title"&gt;&lt;/textarea&gt;
  
          &lt;input type="submit" name="upload" value="Upload" id="upload"&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>One of the dynamic adding functions (this one is for image inputs)</p>
  
  <pre><code>    function addImage() {
      $("form").append('&lt;div&gt;&lt;input type="file" name="items[][image]" id="uploadImage" multiple&gt;&lt;/div&gt;');
  }
  </code></pre>