The values appearing in the PHP operation code feel confused, please help explain.

Source: Internet
Author: User
Tags php operator
Header ("Content-type:text/html;charset=utf-8");
$a = 10;
$b = ' 60 ';
echo "$a + $b =". $a + $b. "
";
echo "$a-$b =". $a-$b. "
";
echo "$a $b = ". $a$b. "
";
echo "$a/$b =". $a/$b. "
";
?>

The last page output has the following values:
70
-50
10*60=600
10/60=0.16666666666667

How are these values derived?

Reply content:

Header ("Content-type:text/html;charset=utf-8");
$a = 10;
$b = ' 60 ';
echo "$a + $b =". $a + $b. "
";
echo "$a-$b =". $a-$b. "
";
echo "$a$b =". $a$b. "
";
echo "$a/$b =". $a/$b. "
";
?>

The last page output has the following values:
70
-50
10*60=600
10/60=0.16666666666667

How are these values derived?

echo "$a + $b =". $a + $b. "
"; execution result (+-) is the same level of execution order left to right)

"$a+$b=" => '10+60='"$a+$b=".$a => '10+60=10'("$a+$b=".$a) + $b => intval('10+60=10') + intval($b) => 10+60 =>70

Click to view PHP operator precedence

$a is the integer type, stored in PHP as Long, $b is a string, when doing arithmetic operations to cast to an integer, the division of the decimal number is stored in double, the rest is mathematical transport forget

Basic operation: Subtraction

In this case, the string is automatically converted into an shaping engagement operation

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.