我有一个test.php
和我有下面的代码
<?php
if(isset($_GET['p']) or $_GET['p'] != null) {
echo $_GET['p'];
} else {
echo "Not found";
}
?>
我在下面的网址则需要输出中列出了被显示
Test 1 : http://localhost/example/test.php
output : Notice: Undefined index: p in R:\xampp\htdocs\example\test.php on line 3
Not found
Test 2 : http://localhost/example/test.php?p
output : blank page
Test 3 : http://localhost/example/test.php?p=
output : blank page
Test 4 : http://localhost/example/test.php?p=1
output : 1
我接受Test 1
和Test 2
是true
但是,当Test 2
和Test 3
失败的解决方案。
哪家运营商更好地使用'和'或''||' – Rafee 2012-04-18 10:55:05
=和''&&'和'或'=''|| ..... [见这里](HTTP:/ /www.php.net/manual/en/language.operators.logical.php) – ManseUK 2012-04-18 11:00:25
Rafee,它们有不同的优先级,这意味着'or'和'||'在某些情况下行为不带括号。使用'&&'和'||'几乎总是更好,并在需要时使用括号。 – 2012-04-18 11:05:24