Re: Array Push and Keys

From: Date: Fri, 29 Aug 2003 15:50:32 +0000
Subject: Re: Array Push and Keys
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-161148@lists.php.net to get a copy of this message
At 00:14 29.08.2003, Mike Morton said: --------------------[snip]-------------------- > >I am trying to loop through some database results to build an array similar >to: > >Array ( > [33]=>Array ( > [usa]=>52.00 > [sa]=>553.00 > ) >) > >And the problem that I am having is that array_push does not want to take >keys when I am using it. --------------------[snip]-------------------- Mike, the solution is quite simple, and is already buried in some of the responses until now. Modifying your sample code, this will work and generate your expected results: $transactions=Array(); While($row=mysql_fetch_array($res) { // array_push($transactions,$row[dealercode]=>Array()); $transactions[$row['dealercode']] = Array(); $another_query=mysql_query("do another query here"); while($morerows=mysql_fetch_array($another_query)) { // array_push($transactions[$row[dealercode], // $morerows[country]=>$morerows[amount]; $transactions[$row['dealercount']][$morerows['country']] = $morerows['amount']; } } Hope this helps, -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#161148) next »