title: How can I sort values from an existing array by data type?
body: <p>I try to determine the data type of each array value from an existing array using foreach() and var_dump().</p>
  
  <p>Let's say I have this array: example:</p>
  
  <pre><code>$arr = ['this','is', 1, 'array', 'for', 1, 'example'];
  </code></pre>
  
  <p>Now I have to take each value of this field and determine its data type.</p>
  
  <p>I try this:</p>
  
  <pre><code>$str = array();
  $int = array();
  
  foreach($arr as $k =&gt; $val) {
       if(var_dump($arr[$k]) == 'string'){
          $str[] = $arr[$k];
       } else {
          $int[] = $arr[$k];
       }
  }
  </code></pre>
  
  <p>In other words, I try to sort the values from an existing array by data type and create a new array with only 'string' values and a second new array with only 'int' values. But it seems that my 'if' condition isn't working properly. How else could I solve this please? Thank you.</p>