note 94092 added to language.operators.precedence

From: Date: Thu, 15 Oct 2009 20:59:56 +0000
Subject: note 94092 added to language.operators.precedence
Groups: php.notes 
Request: Send a blank email to php-notes+get-161790@lists.php.net to get a copy of this message
In the previous example, it is noted that the below doesn't work as expected except in two steps: <?php $ord = $i + 1; $field = "cellID" . $ord; // returns a string $field = "cellID" . $i + 1; // because of the addition it returns an int ?> This doesn't work because the order of operations here is left-to-right; in other words, it appends (concatenates) the contents of $1 to the string, and then it adds (note: addition is a very different operation from concatenation!) 1 to this, which in effect converts the string to an integer to make this operation possible. However, this can be simply done just using parenthesis, that prioritizes the addition operation first: <?php $field = "cellID" . ( $i + 1 ); // returns a string ?> ---- Server IP: 69.147.83.197 Probable Submitter: 69.59.255.20 ---- Manual Page -- http://www.php.net/manual/en/language.operators.precedence.php Edit -- https://master.php.net/note/edit/94092 Del: integrated -- https://master.php.net/note/delete/94092/integrated Del: useless -- https://master.php.net/note/delete/94092/useless Del: bad code -- https://master.php.net/note/delete/94092/bad+code Del: spam -- https://master.php.net/note/delete/94092/spam Del: non-english -- https://master.php.net/note/delete/94092/non-english Del: in docs -- https://master.php.net/note/delete/94092/in+docs Del: other reasons-- https://master.php.net/note/delete/94092 Reject -- https://master.php.net/note/reject/94092 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161790) next »