note 118185 deleted from language.operators.precedence by cmb

From: Date: Thu, 07 Jul 2016 18:41:37 +0000
Subject: note 118185 deleted from language.operators.precedence by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-205920@lists.php.net to get a copy of this message
Note Submitter: nicoolasens at gmail dot com ---- Too add something ton Antistone's comment : {Antistone ¶ 1 year ago BEWARE: Addition, subtraction, and string concatenation have equal precedence! <? $x = 4; echo "x minus one equals " . $x-1 . ", or so I hope"; ?> will print "-1, or so I hope" (Concatenate the first string literal and the value of $x, then implicitly convert that to a number (zero) so you can subtract 1 from it, then concatenate the final string literal.) } You can use the operator "," instead of ".". This way allows you to concatenate the first string literal after $x-1. So the first string literal is note convert to a number (zero) . Solution : <?php $x = 4; echo "x minus one equals " , $x-1 . ", or so I hope"; ?> will print : "x minus one equals 3, or so I hope "

« previous php.notes (#205920) next »