0

As we know that PHP considers -‘ ‘- single quote as a string, and when we put anything inside single quote it’s treated as a string and we can’t add a string with a number, but in this case, I will show you the result which is unexpected that we are able to add number with string and get the accurate result same as adding the number with number.

Let’s see the example below:

<?php
$number1 ='20';
$number2 = 30;
$sum = $number1+$number2;
echo $sum;
var_dump($number1);

Output

50

Debugging Result

string(2) "20"

Note: When I start debugging through PHP inbuilt function var_dump()  if get the data type of $number1 is a string and its length is 2.

So if anyone has a clear logic about it please let me know!!

 

Changed status to publish