Home > php教程 > php手册 > PHP奇趣笔试试题一则

PHP奇趣笔试试题一则

WBOY
Release: 2016-06-06 19:49:08
Original
1426 people have browsed it

$a = 3;$b = 5;if($a = 5 || $b = 7){$a++;$b++;}echo $a, , $b; 输出结果为: A、6 8 B、6 6 C、2 6 D、1 6 E、4 6 想一想..... 答案是1 6 因为($a = 5 || $b = 7) 事实上可以写成($a = (5 || ($b = 7))) ,这里考的是运算优先级。 第二 true === true ,这

$a = 3;
$b = 5;
if($a = 5 || $b = 7){
	$a++;
	$b++;
}
echo $a, ' ', $b;
Copy after login

输出结果为:

A、6 8

B、6 6

C、2 6

D、1 6

E、4 6


想一想.....




































































答案是1 6

因为 ($a = 5 || $b = 7) 事实上可以写成 ($a = (5 || ($b = 7))) ,这里考的是运算优先级。

第二 true++ === true ,这里考的是递增运算。递增、递减运算对布尔值不产生影响,递减运算对NULL不产生影响,对NULL做递增运算会得到1。在处理字符变量的算数运算时,PHP 沿袭了 Perl 的习惯,而非 C 的,字符变量只能递增,不能递减。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template