How do you build up a assoc array, dynamically, using a loop?
The follwing script below is row from the database that is pulled into an array, each row form a two dim array:
$array[] = array($this->list[0] => $data[$this->list[0]], $this->list[1] => $data[$this->list[1]], $this->list[2] => $data[$this->list[2]]);
I need to do the above dynamically while it loops the database.
$key is the index used to increment
$this->list are the column names that are used as the key in the array.
$data[$this->list] is the data that is pulled out from the database
Here is the full method:
public function displayResults(){
$this->time_start = self::getMicrotime();
self::decompileSQL();
self::queryData();
$seed = sprintf("%0.0f", microtime() * 100000);
$key = 0;
$reset = (int) count($this->list) - 1;
$array = array();
for($i = 0; $i < (NUM_ROWS * count($this->list)) && $data =mysql_fetch_assoc($this->result); $i++){
$array[] = array($this->list[$key] => $data[$this->list[$key]]);# <- build the part I need to build up dynamically <- somthing like this
if($key == $reset){
$key = 0;
}else{
$key++;
}
}
$this->time_end = self::getMicrotime();
return $array;
}