Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
109 views
in Technique[技术] by (71.8m points)

How does the following lines of code work in PHP?

So I have a couple of examples with sums in PHP and they are as following:

$var = "0"; // $var = "0" string
$var++; // $var = "1"
$var+=1; // $var = 2 integer
$var += ‘c’; // $var = 2 integer
$var = $var + 1.3; // $var = 3.3 float
$var = 5 + "10 obiecte"; // $var =15
$var = 5 + "obiecte"; // $var =5 integer

But I do not understand the following one: $var = 5 + "10 obiecte"; // $var =15, why is this sum equal to 15? Does PHP takes the integer out of the string and adds it to 5? Is this somehow similar to Python? If there was something like $var = 5 + "1object0", what will the sum be like?

question from:https://stackoverflow.com/questions/65602469/how-does-the-following-lines-of-code-work-in-php

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...