title: How can I turn a value of an array into the key of an array?
body: <p>I am parsing a text file that looks more or less like this:</p>
  
  <pre><code>123.animal=cat
  123.name=fred
  123.food=fish
  345.animal=dog
  petshop=zoonoria
  </code></pre>
  
  <p>This is how I am parsing it:</p>
  
  <pre><code>$file_path = $filename;
  $linesArray = file($file_path);    
  $properties = array();
  
  foreach ($linesArray AS $line) {
  
      if (strlen($line) &amp;&amp; $line[0] == '#') {
          $pdate = substr($line, 1);
          $date = rtrim($pdate);
          $formatted = DateTime::createFromFormat('* M d H:i:s T Y',$date);
          }
  
  
  
      if (false !== ($pos = strpos($line, '='))) {
          $prop=array();    
          $prop[trim(substr($line, 0, $pos))] = trim(substr($line, $pos + 1));
          $lineContArray = explode("=", $line);
          $identArray = explode(".", $lineContArray[0]);
  
          $ident = $identArray[0];
          $type = $identArray[1];     
  
          $value = trim($lineContArray[1]);
  
          $found = 0;
          for ($i=0; $i&lt;count($properties); $i++) {
              if ($properties['number'] == $ident) {
                  $properties[$i][$type]= $value;
                  $found=1;
                  break;
                  }
              }
          if ($found == 0) { 
              if (!empty($type)) { 
                  $properties[] = array('number' =&gt; $ident, $type =&gt; $value); 
                  } else { 
                  $properties[] = array($ident =&gt; $value); } 
              }
          }
  </code></pre>
  
  <p>My result is:</p>
  
  <pre><code>array(3) {
    [0]=&gt;
    array(2) {
      ["number"]=&gt;
      string(3) "123"
      ["animal"]=&gt;
      string(3) "cat"
    }
    [1]=&gt;
    array(2) {
      ["number"]=&gt;
      string(3) "123"
      ["name"]=&gt;
      string(4) "fred"
    }
    [3]=&gt;
    array(2) {
      ["number"]=&gt;
      string(3) "345"
      ["animal"]=&gt;
      string(4) "dog"
    }
    [4]=&gt;
    array(1) {
     ["petshop"]=&gt;
     string(5) "zoonoria"
    }
  }
  </code></pre>
  
  <p>But I need the array to be different, this is the result I like to achieve:</p>
  
  <pre><code>  array(3) {
        [123]=&gt;
        array(3) {
          ["animal"]=&gt;
          string(3) "cat"
          ["name"]=&gt;
          string(4) "fred"
          ["food"]=&gt;
          string(4) "fish"
        }
  
        [345]=&gt;
        array(1) {
          ["animal"]=&gt;
          string(3) "dog"
        }
        [petshop]=&gt;
          string(8) "zoonoria"
        }
      }
  </code></pre>
  
  <p>So my main problem is, I do not know how to turn <code>number</code> into the key. I tried various things, but I failed. I am really happy for every hint.</p>
  
  <hr>
  
  <p>I tried the solution of Svetlio:</p>
  
  <pre><code>$file_path = $filename;
  $linesArray = file($file_path);    
  $properties = array();
  
  
  foreach ( $linesArray as $str) {
          $exp = explode ('=', $str);
          if(count($exp) == 2){
                  $exp2 = explode('.', $exp[0]);
                  if( count($exp2) == 2 ) {
                          $properties [$exp2[0]][$exp2[1]] = $exp[1];
                  } else {   
                          $properties [$exp[0]] = $exp[1];
                  }
          } else {
  
          }
  
  }
  </code></pre>
  
  <p>My result:</p>
  
  <pre><code>array(3) {
    ["123"]=&gt;
    array(3) {
      ["animal"]=&gt;
      string(3) "cat
  "
      ["name"]=&gt;
      string(4) "fred
  "
      ["food"]=&gt;
      string(4) "fish
  "
    }
    [345]=&gt;
    array(1) {
      ["animal"]=&gt;
      string(3) "dog
  "
    }
    ["petshop"]=&gt;
    string(3) "zoonoria
  "
  }
  </code></pre>