How to use array_walk function in class
In the example below dbop is an test class:
class dbop {
$aUpdateData=Array();
public function createOnDupUpdateString($val,$key){
$this->aUpdateData[$key]=$val;
}
public function insertOrUpdOndupKey($aUpdate) {
array_walk($aUpdate, array($this, ‘createOnDupUpdateString’)); // create new array.
}
}
In the function “insertOrUpdOndupKey” for each element of array update function “createOnDupUpdateString” is
applied using “array_walk”.
For the function array_walk, pass the source array ($aUpdate) as first parameter and pass array of class object
“$this” and name of the function to be applied “createOnDupUpdateString” as second parameter.
Categories: PHP