title: Parse string into array of key=>value in PHP
body: <p>I have a string like:</p>
  
  <pre><code>$string = "/key/value/anotherKey/anotherValue/thirdKey/thirdValue"
  </code></pre>
  
  <p>I would like to parse this string to an array of key => value:</p>
  
  <pre><code>array(
      key =&gt; value,
      anotherKey =&gt; anotherValue,
      thirdKey =&gt; thirdValue
  );
  </code></pre>
  
  <p>The only solution I have found is the following, but it seems that there should be an easier way to achieve my goal:</p>
  
  <pre><code>$split = preg_split("[/]", $string, null, PREG_SPLIT_NO_EMPTY);
  $i = 0;
  $j = 1;
  $array = [];
  for(;$i&lt;count($split)-1;){
      $array[$split[$i]] = $split[$j];
      $i += 2;
      $j += 2;
  }
  </code></pre>
  
  <p>I have looked at <a href="https://stackoverflow.com/questions/5397726/parse-query-string-into-an-array">this SO post</a>, put it only works for query strings like:</p>
  
  <pre><code>"key=value&amp;anotherKey=anotherValue&amp;thirdKey=thirdValue"
  </code></pre>
  
  <p>Can anyone guide me towards a more "simple" solution (by that I mean less code to write, the usage of PHP functions and I would like to prevent using loops)? Thank you!</p>