title: PHP Arrays - Optimization
body: <p>A left rotation operation on an array of size n shifts each of the array's elements 1 unit to the left. For example, if 2 left rotations are performed on array [1,2,3,4,5], then the array would become [3,4,1,2,3].
  I am trying to find the most efficient way to solve the below problem. The first line contains two space-separated integers denoting the respective values of n  (the number of integers) and d (the number of left rotations you must perform). 
  The second line contains n space-separated integers describing the respective elements of the array's initial state.</p>
  
  <p>Example input:</p>
  
  <pre><code>5 4
  1 2 3 4 5
  </code></pre>
  
  <p>Example Output:</p>
  
  <pre><code>5 1 2 3 4
  </code></pre>
  
  <p>In most cases, my below code works well, but in terms of execution time, there seems to be some room for improvement - it is currently failing one test with a very large input file (see below) due to Timeout.  </p>
  
  <p>My question is, what can be done to reduce the execution time of the below piece of code? </p>
  
  <pre><code>&lt;?php
  
  $file = file_get_contents ("php://stdin","r");
  $file = explode("\n",$file);
  
  $meta = explode(" ", $file[0]);
  $rotations = $meta[1];
  
  $nums = explode(" ", $file[1]);
  
  while($rotations &gt; 0) {
      $removed = array_shift($nums);
      $nums[] = $removed;
      --$rotations;
  }
  
  echo implode(" ", $nums);
  
  ?&gt;
  </code></pre>
  
  <p>Large Input File</p>
  
  <p><a href="https://hr-testcases-us-east-1.s3.amazonaws.com/24100/input08.txt?AWSAccessKeyId=AKIAJAMR4KJHHUS76CYQ&amp;Expires=1486829605&amp;Signature=CXc9Y6Gro7aDaYt9VsyLgwgn9II%3D&amp;response-content-type=text%2Fplain" rel="nofollow noreferrer">Input File</a></p>