title: Converting array of string to array of integers in PHP
body: <p>I followed the leads in the questions <a href="https://stackoverflow.com/questions/8963910/string-to-array-of-integers-php">this</a> and <a href="https://stackoverflow.com/questions/9593765/how-to-convert-array-values-from-string-to-int">this</a>. </p>
  
  <p>I am trying to convert an input stream of numbers to an array of integers. The code should be self explanatory. </p>
  
  <pre><code>$handle = fopen("php://stdin","r");
  
  print("Enter space separated numbers to be made to an array\n");
  
  $numStream = fgets($handle);
  
  print("Creating array from : {$numStream}\n");
  
  //Using explode to create arrays
  //now we have an array of Strings
  $numArray = explode(" ", $numStream);
  
  var_dump($numArray);
  
  print(getType($numArray[0]));
  print("\n");
  array_walk($numArray, 'intval');
  print(getType($numArray[1]));
  print("\n");
  var_dump($numArray);
  print_r($numArray);
  </code></pre>
  
  <p>I am trying to convert the String array, </p>
  
  <pre><code>array_walk($numArray, 'intval')
  </code></pre>
  
  <p>The last two print blocks prints the type of an array element before and after conversion.</p>
  
  <p>The output is string in both the cases</p>
  
  <pre><code>string
  string
  </code></pre>
  
  <p>I wonder what is going on here? Possibly..</p>
  
  <ol>
  <li>The conversion is wrong</li>
  <li>How the type is checked is wrong</li>
  </ol>
  
  <p>Or possibly both.</p>
  
  <p>Adding the complete input and output, </p>
  
  <pre><code>$ php arrays/arrayStringToInteger.php 
  Enter space separated numbers to be made to an array
  1 1
  Creating array from : 1 1
  
  Array
  (
      [0] =&gt; 1
      [1] =&gt; 1
  
  )
  string
  string
  /home/ubuntu/workspace/basics/arrays/arrayStringToInteger.php:22:
   array(2) {
     [0] =&gt;
      string(1) "1"
     [1] =&gt;
      string(2) "1
   "
  }
   Array
   (
      [0] =&gt; 1
      [1] =&gt; 1
  
  )
  </code></pre>