Does anybody know a fast (performance wise) way to do a large search and replace over a set of array keys. Here's my problem.
I am playing around with a class to speed up some db development work that I do. (This is really about arrays...I promise) I have a function that pulls out a result set and puts them into an array. I would like that array to have 'table.field' style keys. I have the code that does this but I am reunning a loop inside of a loop which on a large result set is going to take a little time. Any ideas on how to accomplish this faster?
//Sets the result variable
function setResult($result)
{
if (is_resource($result)) {
//Store the result and create the result table
$this->_result = $result;
$this->_resultTable = array();
//Make sure it is a valid result
if (mysql_num_rows($result) > 0) {
$this->_fieldNameRevMap = array();
for ($i = 0; $i < mysql_num_fields($result); $i++) {
//Create the reverse index (n to table.field)
$this->_fieldNameRevMap[$i] = mysql_field_table($result, $i) . '.' . mysql_field_name($result, $i);
}
//make sure the result pointer is at the begining
//Then we can begin building our array
mysql_data_seek($result, 0);
while ($temp_arr = mysql_fetch_array($result, MYSQL_NUM)) {
//-------This is the code in question
$temp_arr2 = array();
foreach ($temp_arr as $index => $value) {
$temp_arr2[$this->_fieldNameRevMap[$index]] = $value;
}
$this->_resultTable[] = $temp_arr2;
//-------
}
}
}
}
thanks