Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $data['x'] = $this->x->getResults();
- $data['y'] = $data['x'];
- //some code here to modify $data['y']
- //this causes (undesirably) $data['x] to be modified as well
- $data['x'] = $this->x->getResults();
- $data['y'] = $data['y'];
- foreach($data['x'] as $key=>$row) {
- $data['y'][$key]->some_attr = clone $row->some_attr;
- }
- $data['y'][$key] = clone $row;
- $x = 'x';
- $y = 'y';
- $arr = array(&$x,&$y);
- print_r($arr);
- echo "<br/>";
- $arr2 = $arr;
- $arr2[0] = 'zzz';
- print_r($arr);
- print_r($arr2);
- echo "<br/>";
- $arr2 = array_flip(array_flip($arr));
- $arr2[0] = '123';
- print_r($arr);
- print_r($arr2);
- array_flip()
- $data['x'] = array_flip(array_flip($this->x->getResults()));
- $data['y'] = $data['x'];
- $data['x'] = $this->x->getResults();
- $data['y'] = array();
- foreach($data['x'] as $key => $obj) {
- $data['y'][$key] = clone $obj;
- }
- $v=11;
- $arr[]=&$v;
- $data['x'] = array(
- 'a' => 'test',
- 'b' => 'glop',
- );
- $data['y'] = $data['x'];
- $data['y'][0] = 'Hello, world!';
- var_dump($data['x']); // a => test : no problem with arrays
- $data['x'] = (object)array(
- 'a' => 'test',
- 'b' => 'glop',
- );
- $data['y'] = $data['x'];
- $data['y']->a = 'Hello, world!';
- var_dump($data['x']); // a => Hello, world! : objects are by ref
- $data['x'] = (object)array(
- 'a' => 'test',
- 'b' => 'glop',
- );
- $data['y'] = clone $data['x'];
- $data['y']->a = 'Hello, world!';
- var_dump($data['x']); // a => test : no ref, because of cloning
Add Comment
Please, Sign In to add comment