Doc #62512 [Opn]: Error about array operators documentation

From: Date: Tue, 24 Jul 2012 05:31:33 +0000
Subject: Doc #62512 [Opn]: Error about array operators documentation
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8631@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62512&edit=1 ID: 62512 Updated by: googleguy@php.net Reported by: php at maerdo dot com Summary: Error about array operators documentation Status: Open Type: Documentation Problem Package: Translation problem Operating System: n/a PHP Version: 5.4.4 Block user comment: N Private report: N New Comment: The documentation appears to be correct from the English docs. I can't speak for the French translation, or its accuracy. However, I will note that the addition operator is left-associative (as PHP operators take on precedence and associativity rules mostly from C). So to say that the expression ($arr1 + $arr2) yields left association, is by definition correct. Because $arr1 will be appending all elements in $arr2, that belong to keys which do not exist in $arr1. In your example, the elements of $array1: ( 'a' => 1, 'b' => 2 ) show up first in the resulting array. Any keys found in $array2 that exist in $array1 (in this case 'a'), will simply be ignored and the values of keys found in the second operand, which do not exist in the first operand, will be appended in the yielding expression. This can be a bit confusing when phrased as "left is added to right" or "right is added to left". So instead it's best to explain this from the perspective of an operator as opposed to the perspective of the operands (in a technical documentation). A left associative operator tells us that the operands are grouped to the left in the absence of parenthesis. This means when we spot the operator we need to group its right-hand operand with its left-hand operand when applying the operator. I hope this might help to disambiguate the technical wording found in the French translation. Previous Comments: ------------------------------------------------------------------------ [2012-07-09 09:58:46] php at maerdo dot com URL : http://www.php.net/manual/fr/language.operators.array.php ------------------------------------------------------------------------ [2012-07-08 20:38:21] php at maerdo dot com Description: ------------ This page inform that the addition of two arrays add datas of left array to datas of the right array : " L'opérateur + retourne le tableau de droite auquel sont ajoutés les éléments du tableau de gauche." After test it, i note the behavior is opposite. The addition of these arrays result in the addition of datas of the right array to datas of the left array. <?php $array1=['a'=>1,'b'=>2]; $array2=['a'=>'A','B','C']; var_dump($array1+$array2); // output array(4) { ["a"]=> int(1) ["b"]=> int(2) [0]=> string(1) "B" [1]=> string(1) "C" } ?> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62512&edit=1

« previous php.doc.bugs (#8631) next »