关系运算符===(用于相同的)是否可以与!=运算符互换使用"并获得相同的结果?或者当我执行更大的程序时,我最终会遇到问题吗?
我知道我会在下面的例子中得到相同的结果,这总是如此吗?
//example 1
<?php
$a = 1; //integer
$b = '1'; //string
if ($a === $b) {
echo 'Values and types are same';
}
else {
echo 'Values and types are not same';
}
?>
// example 2
<?php
$a = 1; //integer
$b = '1'; //string
if ($a != $b) {
echo 'Values and types are not same';
}
else {
echo 'Values and types are same';
}
?>
Run Code Online (Sandbox Code Playgroud) 为什么有些变量需要引用而其他变量不需要?我连接到DB变量的示例不需要引号,但是当我选择或插入数据库时,我需要引号.
例:
//variables
$username="username";
$password="password";
$first=$_POST['first'];
$last=$_POST['last'];
//connect to DB
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to connect to database");
//values assigned
$query = "INSERT INTO guestbook VALUES
('','$first','$last','$email','$web','$comment')";
mysql_query($query);
Run Code Online (Sandbox Code Playgroud)