Re: Looping through a records set an putting values into a multi dimensional array

From: Date: Wed, 13 Dec 2000 22:32:14 +0000
Subject: Re: Looping through a records set an putting values into a multi dimensional array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-30192@lists.php.net to get a copy of this message
On Wed, 13 Dec 2000, Stuart Rees wrote: > Hi, > > could someone please give me a solution to my following problem, I'm going > nuts understanding the weird way php handles multi dimensional arrays. > > I'm looping through the results of a select statement I'm running. The > result is returning 3 fields each time it loops, they are $user_id, > $class_id and $info. What I'm trying to do is use $user_id and $class_id as > my two indices for my array and place $info into the array. > > In most other languages I would simply do myarray($user_id, > $class_id)=$info. But clearly you cant do it like that in php. > > Any suggestions are appreciated > Try: $array=Array(); while ($row=xx_fetch_array($result)) { if !isset($array[$row["user_id"]]) $array[$row["user_id"]]=Array(); $array[$row["user_id"]][$row["class_id"]]=$row["info"]; }; -- Ignacio Vazquez-Abrams <ignacio@openservices.net>

« previous php.general (#30192) next »