Hi,

Thursday, May 13, 2004, 9:59:23 PM, you wrote:
Y> Hello everyone.
Y> I am having a stupid problem with a couple of arrays, tried a couple of
Y> things but I am feeling disconcerted.

Y> The thing is, I thought it was possible to create arrays in a dynamic
Y> fashion, as in:
Y> $newarray['newkey'] = "new_value";
Y> And the array would be incremented accordingly.
Y> And afterwards, if I wanted to add a new key to the thing, just doing:
Y> $newarray['anotherkey'] = "anothervalue"; would be enough.
Y> Generally speaking I have been trying that and it was working, but right
Y> now I am having some trouble with this.

Y> I am parsing a kind of referrals log file, and as I get the values I
Y> want to create  a hash with all the values I get into a hash to use
Y> later on.

Y> Each line of the log is processed in a while() loop, and after 
Y> extracting the values for $searchSource, $searchDomain and $searchTerm I
Y> try to create the hash entries with these lines:

Y> 
$table["$searchSource"]["$searchDomain"]["$searchTerm"]["total"]+=$row['order_total'];
Y> $table["$searchSource"]["$searchDomain"]["$searchTerm"]["count"]++;

Y> "total" is an amount that I want to aggregate for each $seachTerm, and
Y> "count" an obvious counter with total hits per $searchTerm/Domain/Source
Y> combination. $table is an array which I create before entering the loop
Y> with: $table = array();

Y> The problem is that I keep getting this warnings and notices:
Y> Notice: Undefined index: GGAW in 
Y> c:\www\deepswarm.co.uk\script\monthlytable.php on line 60

Y> Notice: Undefined index: www.google.com in 
Y> c:\www\deepswarm.co.uk\script\monthlytable.php on line 60

Y> Notice: Undefined index: obscuredterm in 
Y> c:\www\deepswarm.co.uk\script\monthlytable.php on line 60

Y> Notice: Undefined index: total in 
Y> c:\www\deepswarm.co.uk\script\monthlytable.php on line 60

Y> Notice: Undefined index: count in 
Y> c:\www\deepswarm.co.uk\script\monthlytable.php on line 62

Y> Using the "@" operator the scripts works perfectly, but I still want to
Y> know why I am generating so many notices, and if there is any other
Y> "cleaner" way of doing things.

Y> I can't create the hash with all necessary keys beforehand because I
Y> won't know the values until runtime, so doing something like:
Y> $table = array ("GGAW" =>
Y>              array ("www.google.com" =>
Y>                      array ("obscuredterm" =>
Y>                      array("total", "count")
Y>                      )
Y>              )
Y>      )
Y> before going into the actual loop is out of the question.

Y> Any ideas? This is probably very obvious, but I keep hitting my head
Y> against the wall. Light would be greatly appreciated.

Y> Thanks for your help.

Y> Regards,

Y> I.-


you have to do it like this:

$table["$searchSource"]["$searchDomain"]["$searchTerm"]["total"]=
(isset($table["$searchSource"]["$searchDomain"]["$searchTerm"]["total"]))? 
$table["$searchSource"]["$searchDomain"]["$searchTerm"]["total"] + $row['order_total'] 
: 1;

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to