title: Php prefix tree implementation versus assoc array
body: <p><strong>UPD:</strong> I moved original question to <a href="https://codereview.stackexchange.com/questions/127055/building-tree-graph-from-dictionary-performance-issues">https://codereview.stackexchange.com/questions/127055/building-tree-graph-from-dictionary-performance-issues</a></p>
  
  <p>Here is a short version, without codes.</p>
  
  <p>I'm trying to build a prefix tree from dictionary. So, using the following dictionary <code>'and','anna','ape','apple'</code>, graph should look like this:
  <a href="https://i.stack.imgur.com/ejI22.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ejI22.jpg" alt="graph"></a>
  I've tried 2 approaches: using associative array and using self-written tree/node classes.</p>
  
  <p>Note: original dictionary is something about 8 MB and contains >600000 words.</p>
  
  <p><strong>Question:</strong> is there any good(fast/efficient) way to do it? </p>
  
  <p>I've tried so far:</p>
  
  <ul>
  <li><p>php associative arrays (they are not very flexible for future work with this graph).</p></li>
  <li><p>self-written Tree/Node classes (performance issues - execution time rises by up to 7x, memory usage rises by 2x even without implementing anything except just <code>inserting</code> function).</p></li>
  </ul>
  
  <p>Sample codes are available on codereview (the very first link in question)</p>