Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $a1 = array('foo');
- $a2 = $a1;
- $a2[0] = 'bar';
- // now $a1[0] is foo, and $a2[0] is bar. The array is copied
- $a1 = array('foo');
- $a2 = $a1; // <-- this should make a copy
- // but $a1 and $a2 point to the same data internally
- $a2[0] = 'bar';
- // now $a1[0] is foo, and $a2[0] is bar. The array is really copied
- <?php
- ini_set('memory_limit', '64M');
- function ttime($m) {
- global $s;
- echo $m.': '.(microtime(true) - $s).'<br/>';
- $s = microtime(true);
- }
- function aa($a) {
- return $a;
- }
- $s = microtime(true);
- for ($i = 0; $i < 200000; $i++) {
- $array[] = $i;
- }
- ttime('Create');
- $array2 = aa($array); // or $array2 = $array
- ttime('Copy');
- $array2[1238] = 'test';
- ttime('Modify');
- Create: 0.0956180095673
- Copy: 7.15255737305E-6
- Modify: 0.0480329990387
Add Comment
Please, Sign In to add comment