I'm writing a recursive function which iterates through a data array containing indexed and associative arrays. When an associative array of the form ['name->i,'value'->j] meets certain criteria I want to add an additional key/val pair to the array ('insert'->1).
Further iterations of updateDB() call fieldSetForTable($key,$tableArrayRef) which recursively checks the data array, starting from reference $tableArrayRef for arrays containing the same key value as $key. If found, and the ['insert'] key/val is set, the function returns true.
The problem is, as coded below, the 'insert' keys do no tappear in the array structure until updateDB() has finished it's recursion. I need the 'insert' data to be added immediately so it is available to further iterations and recursions of updateDB().
I know this is possible by passing reference vars but can't seem to get it to work!
Many thanks for any help you can give. Code below
Matt
function updateDB(&$data_array,$sql,$tableName,$tableArrayRef){
foreach($data_array as $key=>$value){
// update our array pointer for a new db table
if($this->conf->get('dbTagToTable.'.$key)){
$tableName = $this->conf->get('dbTagToTable.'.$key);
$tableArrayRef = $data_array[$key];
}
if(is_array($data_array[$key]) && isset($data_array[$key]['value'])){
$dbfields = $this->fieldsInTable($tableName);
// if the field exists in the current table...
if(in_array($key,$dbfields)){
// and not been populated...
// returns true if ['insert'] has already been set to 1
// for any assoc value in $tableArrayRef for key $key
if(!@$this->fieldSetForTable($key,$tableArrayRef)){
/****** This value is set on completion of updateDB *****/
/****** but is not immediately avail to fieldSetForTable() *****/
/****** while updateDB() is recursing - I want it to be! *****/
$data_array[$key]['insert']=1;
}
}
} else if(is_array($data_array[$key][0])){
// Other code here...
}else {
// Other code here...
}
}
return //some sql here;
}