title: How to convert an array into key-value pairs in PHP
body: <p>Here, I have an array.</p>
  <pre><code>$arr = array(
  
    &quot;action: Added; amount: 1; code: RNA1; name: Mens Organic T-shirt; colour: White; size: XL&quot;,
  
    &quot;action: Subtracted; amount: 7; code: RNC1; name: Kids Basic T-shirt; colour: Denim Blue; size: 3-4y&quot;,
  
    &quot;action: Added; amount: 20; code: RNV1; name: Gift Voucher; style: Mens; value: £20&quot;,
  </code></pre>
  <p>I have taken some steps to try and convert this array into a key-pair array by doing the following:</p>
  <pre><code>// Split the array into strings.
  $imploded = implode(&quot; &quot;,$arr);
  //echo $imploded;
  // Seperate the strings by the &quot;;&quot; character.
  $exploded = explode(&quot;; &quot;,$imploded);
  //print_r($exploded);
  // The elements are now in an array.
  // Here I need to separate them into key value pairs.
  </code></pre>
  <p>I used the $explode function to split the $imploded string by the &quot;; &quot; character to make the data easier to work with. This is the result of printing the $exploded array:</p>
  <pre><code>Array ( [0] =&gt; action: Added [1] =&gt; quantity: 1 [2] =&gt; item_code: RNA1 [3] =&gt; product_name: Mens Organic T-shirt [4] =&gt; colour: White [5] =&gt; size: XL action: Subtracted [6] =&gt; quantity: 7 [7] =&gt; item_code: RNC1 [8] =&gt; product_name: Kids Basic T-shirt [9] =&gt; colour: Denim Blue [10] =&gt; size: 3-4y action: Added [11] =&gt; quantity: 20 [12] =&gt; item_code: RNV1 [13] =&gt; product_name: Gift Voucher [14] =&gt; style: Mens [15] =&gt; value: £20 )
  </code></pre>
  <p>I have tried experimenting with the array_combine function, however I don't think it is working because the keys and pairs are in the same elements.</p>
  <pre><code>$result = array(
      array_combine($exploded[0], $exploded[1]));
  //print_r($result);
  </code></pre>
  <p>I could potentially try splitting the elements with the &quot;: &quot; character, but i'm not sure how i'd go about doing this. I'm also quite new to PHP, so i'd appreciate some simple code and explanations :)</p>
  <p>EDIT: I'd like the resulting array to look something like this...</p>
  <pre><code>    'action'    =&gt;   '',
      'quantity'  =&gt;   '',
      'item_code'     =&gt;   '',
      'product_name'  =&gt;   '',
      'colour'    =&gt;   '',
      'size'      =&gt;   '',
  </code></pre>