| Newsgroups |
php.notes |
| Message-ID |
<[email protected]> |
You should be careful when using pointers. The following example shows how an array is unintentionally distorted if the pointer variable is not treated with unset
<?php
echo '<pre>';
$arr = array ( 'a' => 'a' , 'b' => 'b' ) ;
var_dump ($arr) ;
foreach ( $arr as $index => &$data ) {}
var_dump ($arr) ;
// unset($data);
foreach ( $arr as $index => $data ) {}
var_dump ($arr) ;
?>
Output:
array(2) {
["a"]=>
string(1) "a"
["b"]=>
string(1) "b"
}
array(2) {
["a"]=>
string(1) "a"
["b"]=>
&string(1) "b"
}
array(2) {
["a"]=>
string(1) "a"
["b"]=>
&string(1) "a"
}
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 212.91.255.90)
----
Manual Page -- https://php.net/manual/en/language.references.php
Edit -- https://main.php.net/note/edit/130363
Del: integrated -- https://main.php.net/note/delete/130363/integrated
Del: useless -- https://main.php.net/note/delete/130363/useless
Del: bad code -- https://main.php.net/note/delete/130363/bad+code
Del: spam -- https://main.php.net/note/delete/130363/spam
Del: non-english -- https://main.php.net/note/delete/130363/non-english
Del: in docs -- https://main.php.net/note/delete/130363/in+docs
Del: other reasons-- https://main.php.net/note/delete/130363
Reject -- https://main.php.net/note/reject/130363
Search -- https://main.php.net/manage/user-notes.php