PHP big array manipulation
<p>I have a very big array stored in memory after reading a whole file in an array (as hex) like this : </p>

<pre><code>$bin_content = fread(fopen($filename,"r"),filesize($filename));
$hex_decode = explode(" ",chunk_split(bin2hex($bin_content),2," "));
unset($bin_content);

function myfunction($i) {
  global $hex_decode;
  // stuff here 
}
</code></pre>

<p>When I create a function that uses this <code>$hex_decode</code> array as global ... the script runs like forever (very slow) but if i call that function passing the <code>$hex_decode</code> as a parameter ( <code>myfunction($i,$hex_decode) instead of myfunction($i) in which $i is a pointer</code>) , things are more faster . </p>

<p>Can anyone explain why ? And is there any way to speed the script by reading that file in a different method . </p>

<p>I need to have the whole file in that array rather that line by line , because I'm building a custom ASN.1 decoder and i need to have it all .</p>
