本文介绍了为什么“回声'2'. print(2)+ 3“;打印521?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

有人可以告诉下面表达式的内部过程吗?

Can anybody tell the internal procedure of the below expression?

<?php echo '2' . print(2) + 3; ?>
// outputs 521

推荐答案

回显由以下内容组成的串联字符串:

Echo a concatenated string composed of:

字符串"2"函数print('2')的结果,该结果将返回true,并将其字符串化为1字符串"3"

The string '2'The result of the function print('2'), which will return true, which gets stringified to 1The string '3'

现在,操作顺序在这里真的很有趣,根本不能以521结尾!让我们尝试一种变体,以找出问题所在.

Now, the order of operations is really funny here, that can't end up with 521 at all! Let's try a variant to figure out what's going wrong.

echo'2'.print(2)+ 3;这将产生521

echo '2'.print(2) + 3;This yields 521

PHP正在将其解析为:

PHP is parsing that, then, as:

echo'2'. (print('2')+'3'))答对了!左边的打印首先被评估,打印为"5",这使我们离开

echo '2' . (print('2') + '3'))Bingo! The print on the left get evaluated first, printing '5', which leaves us

echo'1'.打印('2')然后对左侧的图片进行评估,因此我们现在打印了"52",剩下的是

echo '1' . print('2')Then the left print gets evaluated, so we've now printed '52', leaving us with

echo'1'. '1';成功. 521.

echo '1' . '1' ;Success. 521.

我强烈建议不要回显打印结果,也不要打印回显结果.首先,这样做是毫无意义的.

I would highly suggest not echoing the result of a print, nor printing the results of an echo. Doing so is highly nonsensical to begin with.

这篇关于为什么“回声'2'. print(2)+ 3“;打印521?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:09