note 107132 added to language.references.whatdo
| From: | Hamal at example dot com | Date: | Tue, 10 Jan 2012 04:40:00 +0000 |
| Subject: | note 107132 added to language.references.whatdo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185512@lists.php.net to get a copy of this message | ||
About elrah's examples
Just like PHP manual says "the reference behavior of arrays is defined in an element-by-element
basis".
If make a little change on example two, which adding one more element in $arr3, we can see this
statement clearer.
// Example one
$arr1 = array(1);
echo "\nbefore:\n";
echo "\$arr1[0] == {$arr1[0]}\n";
echo "<br />";
$arr2 = $arr1;
$arr2[0]++;
echo "\nafter:\n";
echo "\$arr1[0] == {$arr1[0]}\n";
echo "\$arr2[0] == {$arr2[0]}\n";
echo "<br />";
// Example two
$arr3 = array(1, 3); //Add $arr3[1] = 2
$a =& $arr3[0];
echo "\nbefore:\n";
echo "\$a == $a\n";
echo "\$arr3[0] == {$arr3[0]}\n";
echo "<br />";
$arr4 = $arr3;
$arr4[0]++;
$arr4[1]++;
echo "\nafter:\n";
echo "\$a == $a\n"; //echo 2
echo "\$arr3[0] == {$arr3[0]}\n"; //echo 2
echo "\$arr4[0] == {$arr4[0]}\n"; //echo 2
echo "\$arr3[1] == {$arr3[1]}\n"; //echo 3
echo "\$arr4[1] == {$arr4[1]}\n"; //echo 4
This is about the structure of an array and a variable in PHP.
If you are interested in what a PHP array really is, check the following article out:
http://nikic.github.com/2011/12/12/How-big-are-PHP-arrays-really-Hint-BIG.html
----
Server IP: 69.147.83.197
Probable Submitter: 111.250.73.120
----
Manual Page -- http://www.php.net/manual/en/language.references.whatdo.php
Edit -- https://master.php.net/note/edit/107132
Del: integrated -- https://master.php.net/note/delete/107132/integrated
Del: useless -- https://master.php.net/note/delete/107132/useless
Del: bad code -- https://master.php.net/note/delete/107132/bad+code
Del: spam -- https://master.php.net/note/delete/107132/spam
Del: non-english -- https://master.php.net/note/delete/107132/non-english
Del: in docs -- https://master.php.net/note/delete/107132/in+docs
Del: other reasons-- https://master.php.net/note/delete/107132
Reject -- https://master.php.net/note/reject/107132
Search -- https://master.php.net/manage/user-notes.php