note 118185 added to language.operators.precedence

From: Date: Thu, 22 Oct 2015 09:17:19 +0000
Subject: note 118185 added to language.operators.precedence
Groups: php.notes 
Request: Send a blank email to php-notes+get-204003@lists.php.net to get a copy of this message
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 " ---- Server IP: 72.52.91.14 Probable Submitter: 90.14.112.26 ---- Manual Page -- http://php.net/manual/en/language.operators.precedence.php Edit -- https://master.php.net/note/edit/118185 Del: integrated -- https://master.php.net/note/delete/118185/integrated Del: useless -- https://master.php.net/note/delete/118185/useless Del: bad code -- https://master.php.net/note/delete/118185/bad+code Del: spam -- https://master.php.net/note/delete/118185/spam Del: non-english -- https://master.php.net/note/delete/118185/non-english Del: in docs -- https://master.php.net/note/delete/118185/in+docs Del: other reasons-- https://master.php.net/note/delete/118185 Reject -- https://master.php.net/note/reject/118185 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204003) next »