title: errors received when trying to set hyperlinks
body: <p>I am trying to set each image name as a hyperlink. But problem is I am receiving 3 errors, 2 are undefined erros and the other one is expecting 1 parameter.</p>
  <p>Current code which is not working:</p>
  <pre><code>    &lt;table id=&quot;tableqanda&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;
      &lt;thead&gt;
      &lt;tr&gt;
          &lt;th width=&quot;11%&quot; class=&quot;image&quot;&gt;Image&lt;/th&gt;
      &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;/table&gt;
      &lt;div id=&quot;tableqanda_onthefly_container&quot;&gt;
      &lt;table id=&quot;tableqanda_onthefly&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;
      &lt;tbody&gt;
          &lt;?php
          
  function imageName( $imgitem ) {
      return htmlspecialchars($imgitem); //432
  }
  
          
            foreach ($arrQuestionId as $key=&gt;$question) {
          echo '&lt;tr class=&quot;tableqandarow&quot;&gt;'.PHP_EOL;
          echo '&lt;td width=&quot;11%&quot; class=&quot;imagetd&quot;&gt;';
          
          if (empty($arrImageFile[$key])) {
              echo '&amp;nbsp;';
          } else {
      echo '&lt;ul class=&quot;qandaul&quot;&gt;&lt;li&gt;&lt;a href=&quot;previewImage.php?imgId=[' . $imgitem . ']&quot; target=&quot;_blank&quot;&gt;'; //line 456
      echo implode('&lt;/li&gt;\n&lt;li&gt;&lt;/a&gt;&lt;a href=&quot;previewImage.php?imgId=[' . $imgitem . ']&quot; target=&quot;_blank&quot;&gt;', imageName($arrImageFile[$key]) ); //line 457
      echo '&lt;/li&gt;&lt;/ul&gt;&lt;/a&gt;';
          }
          echo '&lt;/td&gt;';
          echo '&lt;/tr&gt;'.PHP_EOL;
          }
  ?&gt;
      &lt;/tbody&gt;
      &lt;/table&gt;
      &lt;/div&gt;
  </code></pre>
  <p>Errors received:</p>
  <p>Warning: htmlspecialchars() expects parameter 1 to be string, array given in ... on line 432</p>
  <p>Notice: Undefined variable: imgitem in ... on line 456</p>
  <p>Notice: Undefined variable: imgitem in ... on line 457</p>
  <hr />
  <h3>Formatted Code:</h3>
  <pre><code>&lt;table id=&quot;tableqanda&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th width=&quot;11%&quot; class=&quot;image&quot;&gt;Image&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
  &lt;/table&gt;
  &lt;div id=&quot;tableqanda_onthefly_container&quot;&gt;
      &lt;table id=&quot;tableqanda_onthefly&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;
          &lt;tbody&gt;
              &lt;?php
                  function imageName( $imgitem ) {
                      return htmlspecialchars($imgitem); //432
                  }
                  foreach ($arrQuestionId as $key=&gt;$question) {
                      echo '&lt;tr class=&quot;tableqandarow&quot;&gt;'.PHP_EOL;
                      echo '&lt;td width=&quot;11%&quot; class=&quot;imagetd&quot;&gt;';
                      if (empty($arrImageFile[$key])) {
                          echo '&amp;nbsp;';
                      } else {
                          echo '&lt;ul class=&quot;qandaul&quot;&gt;&lt;li&gt;&lt;a href=&quot;previewImage.php?imgId=[' . $imgitem . ']&quot; target=&quot;_blank&quot;&gt;'; //line 456
                          echo implode('&lt;/li&gt;\n&lt;li&gt;&lt;/a&gt;&lt;a href=&quot;previewImage.php?imgId=[' . $imgitem . ']&quot; target=&quot;_blank&quot;&gt;', imageName($arrImageFile[$key]) ); //line 457
                          echo '&lt;/li&gt;&lt;/ul&gt;&lt;/a&gt;';
                      }
                      echo '&lt;/td&gt;';
                      echo '&lt;/tr&gt;'.PHP_EOL;
                  }
              ?&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  <p><strong><code>var_dump</code> results:</strong></p>
  <p>From the var_dump specified the results are below:</p>
  <pre><code>array(2) { 
    [72]=&gt; array(2) { 
      [0]=&gt; string(16) &quot;Lighthouse_4.jpg&quot; 
      [1]=&gt; string(12) &quot;Tulips_3.jpg&quot; 
    } 
    [73]=&gt; array(1) { 
      [0]=&gt; string(16) &quot;Hydrangeas_3.jpg&quot; 
    } 
  }
  int(73)
  </code></pre>
  <p><strong>UPDATE:</strong></p>
  <p>With Praveen's code I am getting an error stating:</p>
  <p><code>Fatal error: Cannot redeclare imageName() (previously declared in ...:451) in ... on line 451</code></p>
  <p>Below is code:</p>
  <pre><code>&lt;table id=&quot;tableqanda&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th width=&quot;11%&quot; class=&quot;image&quot;&gt;Image&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
  &lt;/table&gt;
  &lt;div id=&quot;tableqanda_onthefly_container&quot;&gt;
      &lt;table id=&quot;tableqanda_onthefly&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;
          &lt;tbody&gt;
    //line 451          &lt;?php function imageName( $imgitem ) { return htmlspecialchars($imgitem);
              } foreach ($arrQuestionId as $key=&gt;$question) { echo '
              &lt;tr class=&quot;tableqandarow&quot;&gt;'.PHP_EOL; echo '
                  &lt;td width=&quot;11%&quot; class=&quot;imagetd&quot;&gt;'; function imageName( $imgitem ) { return htmlspecialchars($imgitem);
                      function getImgLink ( $imgKey ) { return $imgKey[0]; if (empty($arrImageFile[$key]))
                      { echo '&amp;nbsp;'; } else { echo '
                      &lt;ul class=&quot;qandaul&quot;&gt;
                          &lt;li&gt;
                              &lt;a href=&quot;previewImage.php?imgId=[' . getImgLink($arrImageFile($key)) . ']&quot;
                              target=&quot;_blank&quot;&gt;'; echo implode('&lt;/li&gt;\n
                          &lt;li&gt;
                              &lt;/a&gt;
                              &lt;a href=&quot;previewImage.php?imgId=[' . getImgLink($arrImageFile($key)) . ']&quot;
                              target=&quot;_blank&quot;&gt;', imageName($arrImageFile[$key]) ); echo '&lt;/li&gt;
                      &lt;/ul&gt;
                      &lt;/a&gt;'; } echo '&lt;/td&gt;'; } } echo '&lt;/tr&gt;'.PHP_EOL; } ?&gt;&lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>