php_joe Posted December 28, 2007 Share Posted December 28, 2007 I have a variable with a very large key and it gets parsed in a strange way. Here is the code: <? $line[11988600574445] = "line one"; foreach($line as $key => $msg) echo "$key|$msg<br>\n"; ?> and it outputs: -2147483648|line one If I have: <? $line[11988600574445] = "line one"; $line[11988600942070] = "line two"; $line[1198860109608] = "line three"; foreach($line as $key => $msg) echo "$key|$msg<br>\n"; ?> I end up with just one line on the page: -2147483648|line three Which, as you can see, is the last value in the array and that's not the right key. What's going on? Quote Link to comment https://forums.phpfreaks.com/topic/83486-solved-large-key/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 28, 2007 Share Posted December 28, 2007 The numeric index values exceed what can be represented in an integer. PHP is likely generating an error on the first two lines (check your web server log for errors.) The third one is small enough a value that it is within the +/- range of a signed integer and looks like a negative value because the MSB is set. Use quited strings as indexes to fix your problems. As to why the first single example outputs something? It's anyone's guess. Probably has something to do with the error response code in php or the code you posted is not exactly the code that generated the output. Quote Link to comment https://forums.phpfreaks.com/topic/83486-solved-large-key/#findComment-424753 Share on other sites More sharing options...
php_joe Posted December 28, 2007 Author Share Posted December 28, 2007 Thanks. I think I've found a workaround. Quote Link to comment https://forums.phpfreaks.com/topic/83486-solved-large-key/#findComment-424754 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.