title: Validating array only integer number in PHP
body: <p>I want to validate an array so only integer number is allowed.
  I've tried some ways but still doesn't get the result I want.</p>
  <p>I have array like this:</p>
  <pre><code>array(5) { 
     [0]=&gt; string(3) &quot;312&quot; 
     [1]=&gt; string(2) &quot;41&quot; 
     [2]=&gt; string(2) &quot;44&quot; 
     [3]=&gt; string(2) &quot;22&quot; 
     [4]=&gt; string(2) &quot;22&quot; 
  }
  </code></pre>
  <p>First I'm writing a code like this:</p>
  <pre><code>$total= $_POST[&quot;total&quot;];
  if (!preg_match (&quot;/^[0-9]*$/&quot;, $total) ) {  
          $ErrMsg = &quot;Only numeric value is allowed.&quot;;
          echo $ErrMsg;
  }
  </code></pre>
  <p>I got an error that said only string allowed for !preg_match function, this is because $total is an array.</p>
  <p>Next is I'm trying to convert $total to a string.</p>
  <pre><code>$total= $_POST[&quot;total&quot;];
  $stringTotal = implode(&quot;, &quot;, $total);
      
      if (!preg_match (&quot;/^[0-9]*$/&quot;, $total) ) {  
          $ErrMsg = &quot;Only numeric value is allowed.&quot;;
          echo $ErrMsg;
  </code></pre>
  <p>The code above no longer give error, but the result still wrong. $total is a string so the result will false.</p>
  <p>Is there's any way how to do it? Thank you</p>