I Have a ListNode built that has the following structure:
class MyNode {
private $weight;
private $children;
private $t1;
private $t2;
private $t3;
***
more variables
***
function __constructr($weight, $t1, $t2, $t3, $children = array()) {
$this->weight = $weight;
$this->children = $children;
$this->t1 = $t1;
$this->t2 = $t2;
$this->t3 = $t3;
}
Now I create 5 Nodes that have same data but different weight.
$n1 = new MyNode(25, 't_1', 't_2', 't_3');
$n2 = new MyNode(30, 't_1', 't_2', 't_3');
$n3 = new MyNode(49, 't_1', 't_2', 't_3');
$n4 = new MyNode(16, 't_1', 't_2', 't_3');
$n5 = new MyNode(62, 't_1', 't_2', 't_3');
Note that the t1, t2 and t3 can be different but for this 5 nodes they are same. Instead of doing above i want to do the following using some kind of clone function
$n1 = new MyNode(25, 't_1', 't_2', 't_3');
$n2 = $n1->clone(array('weight' => 30));
$n3 = $n2->clone(array('weight' => 49));
$n4 = $n4->clone(array('weight' => 16));
$n5 = $n5->clone(array('weight' => 62));
clone function takes array of keys being the variable names inside MyNode that i want to change and their values. so array('weight' => 30) should change $this->weight = 30; Im stuck accessing the variable from array. It should create a new node with all the values being same as its current node but modify only the ones that are in array.
function clone($changeVariables) {
-----
}