I have a script with a line like this:
I use the web server error logs for debugging and apparently the warnings are tuned way up. Everytime a new value of $id is encountered, I get a warning saying I'm incrementing a variable that doesn't exist. I can do this:
Code: Select all
if (isset($array[$id])) $array[$id]++; else $array[$id]=1;
but that seems like overkill. I can't initialize the array because I have no way to predict the values of $id. Is there a more correct way to do what I'm trying to do or is that second line the best way? Thanks.