+ 3
What will be the output???
<?php $num1 = "1"; $num2 = "2"; print $num1 + $num2; ?>
5 Answers
+ 9
Here, the numbers 1 and 2 stored in variables $num1 and $num2 are added using arithmetic addition operator(+).
so the output will become 3
if you want to concatenate the numbers then you should place a period (.) operator
to the addition of variables using a period.During this make it sure that you put your variable addition in the parenthesis like ($num1+$num2), otherwise instead of the sum of 2 variables only the value of second variable will be printed.
+ 3
How does it works??
https://code.sololearn.com/w74N2X9ri7aO/?ref=app
still it is a string!!!
+ 2
The output will be 3 because the char values are numerical ones.
Playing with a combination of strings which whether contain numerical values or not, I found out the next:
<?php
/* using arithmetic addition for */
$a="1";
$b="2";
print $a+$b;//print 3
print "\n";
$a="3ddas";
$b="2fdgdd";
print $a+$b; //print 5 because for every variable, php will obtain the numerical value of the beginning of each string. In this case 3 and 2 fot which the add is the mentioned value.
print "\n";
$a="fds3ddas";
$b="fdgdd";
print $a+$b; // if the strings dont contain a numerical value or they are after a char o string or simply they dont contain any numerical one, then the add will be zero.
+ 2
Answer may be 3 nu nenaikiren kaa...
correct aaa...??
+ 2
@purushoth sharma it's correct