note 94092 deleted from language.operators.precedence by danbrown

From: Date: Thu, 15 Oct 2009 21:02:26 +0000
Subject: note 94092 deleted from language.operators.precedence by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-161791@lists.php.net to get a copy of this message
Note Submitter: Robert ---- 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 ?>

« previous php.notes (#161791) next »