Re: Wierd ass code...
| From: | Satyam | Date: | Sat, 13 May 2006 20:07:32 +0000 |
| Subject: | Re: Wierd ass code... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-236121@lists.php.net to get a copy of this message | ||
----- Original Message ----- From: "Satyam" <Satyam@satyam.com.ar>
To: "Ryan A" <genphp@yahoo.com>; "php php" <php-general@lists.php.net>
Sent: Saturday, May 13, 2006 9:53 PM
Subject: Re: [PHP] Wierd ass code...
----- Original Message ----- From: "Ryan A" <genphp@yahoo.com> To: "php php" <php-general@lists.php.net> Sent: Saturday, May 13, 2006 9:20 PM Subject: [PHP] Wierd ass code...SatyamHey, Been reading some other code that I got from the net, and have come across some wierd looking code, would appreciate it if someone could explain it to me: $hits = array(); $bytes = array(); $blocked = array(); $baps = array(); $bapm = array(); So far so good.... then further down: // Add to the running totals @$hits["$username|$subnet"]++; @$bytes["$username|$subnet"]+=$byte; @$baps["$username|$subnet|$this_second"]++; @$bapm["$username|$subnet|$this_minute"]++; What kind of arrays are the above? I have never seen nor worked with arrays like them before. If you can point me to a particular place in the manual or a few URLs too would be appreciated. Thanks, RyanI don't think there is nothing special with the arrays, he is just coding some information into strings, with the vertical bar as separator, and using this as the keys to several arrays where he is collecting some statistical information, such as (it would seem to me) - number of hits by user and subnet - number of bytes by user and subnet - number of hits per user and subnet per second - number of hits per user and subnet per minute I would assume that the variables $this_second and $this_minute are absolute numbers counted from a particular time, not seconds from 0 to 60 within the minute. Likewise for the minutes. I assume that the @ in front is to avoid the error of trying to increment a value that is not yet set. I guess that this same thing could have been achieved with multidimensional arrays but either concatenating the variables into a single string is faster or some other reason that makes sense for the application, such as being able to sort by keys in just one operation. Satyam Of course, another possibility is that the author does not know how to handle multidimensional arrays (just to say it before anyone else points an obvious alternative)