Forum Moderators: coopster

Message Too Old, No Replies

PHP Array Help $key=>$value

         

boxfan

5:00 pm on Jun 24, 2009 (gmt 0)

10+ Year Member



I am trying to do the following:


while ($row = $conn->fetch_object ()) {
foreach($row as $key=>$value) { $$key[] = $value; }
}

Obviously the $$key[] = $value is incorrect but you can see what I'm trying to accomplish. I want the DB field names to become arrays holding the multiple rows of data without having to specifically assign like this


$orderDate[] = $row->orderDate;
$orderAmount[] = $row->orderAmount;

Any ideas?

Thanks.

boxfan

6:05 pm on Jun 24, 2009 (gmt 0)

10+ Year Member



Nevermind. I figured it out.

while($row = $conn->fetch_array()){
foreach($row as $key => $value){
if(!is_numeric($key)){
$array[$key][] = $value;
$$key = $array[$key];
}
}
}

Thanks